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

How to support transaction? #76

Open
shenweijiekdel opened this issue May 14, 2023 · 1 comment
Open

How to support transaction? #76

shenweijiekdel opened this issue May 14, 2023 · 1 comment

Comments

@shenweijiekdel
Copy link

No description provided.

@martinyonatann
Copy link

if the transaction only handles one repository, you can use begin & comit, but if you need to perform transactions for more than one repository function, you can handle it in the usecase by defining a new repository transaction.

type (
	UseCases interface{
		ExampleImpl(context.Context)error
	}

	usecase struct{
		repo Repositories
		conn sqlx.DB
	}
)

func NewUsecase()UseCases{
	return &usecausecase{}
}

func(uc *usecase)ExampleImpl(context.Context)error{
	//create begin from usecase.conn

	// defer rollback 

	//call repository function
}`

`

I don't know if this method is clean or not, but at least it solves the problem.

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

2 participants