Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction in postgresql is failing. #979

Open
sumit7577 opened this issue Jan 31, 2025 · 0 comments
Open

Transaction in postgresql is failing. #979

sumit7577 opened this issue Jan 31, 2025 · 0 comments

Comments

@sumit7577
Copy link

whenever i try to do transactions with beego orm in postgres database its failing and saying ...""""[ORM]2025/01/30 23:51:11 last insert id is unavailable 58 LastInsertId is not supported by this driver"""
here is code.

func (um *UserManager) CreateUser() (*User, error) {
o := orm.NewOrm()
err := o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
hashedPassword, err := hashPassword(um.User.Password)

	if err != nil {
		return err
	}
	username := generateRandomUsername(um.User.Name)
	um.User.Password = hashedPassword
	um.User.Username = username
	_, err = txOrm.Insert(um.User)

	if err != nil {
		return err // This will trigger a rollback
	}
	authToken, nil := generateAuthToken()
	authEntry := &AuthToken{
		Key:     authToken,
		User:    um.User,
		Created: time.Now(),
	}
	_, err = txOrm.Insert(authEntry)

	if err != nil {
		return err
	}
	return nil
})

if err != nil {
	return nil, err
}

return um.User, nil

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant