go-rel / rel

:gem: Modern ORM for Golang - Testable, Extendable and Crafted Into a Clean and Elegant API
https://go-rel.github.io/
MIT License
744 stars 58 forks source link

Transactions doc please clarify #327

Closed fairking closed 1 year ago

fairking commented 1 year ago

Hi everyone.

I am struggling with understanding the documentation about transactions: https://go-rel.github.io/transactions/

The example shows the line Process(ctx, transaction). Where is that transaction value coming from, and why it passed withing the Update() method?

Also another question: Should I create a new context.Context for every transaction or I can use the same one for all my transactions?

Fs02 commented 1 year ago

oh, sorry for miss leading example

transaction in this call Process(ctx, transaction) refers to transaction object/table, it's not db transaction

Should I create a new context.Context for every transaction or I can use the same one for all my transactions?

you need to use context that passed inside repo.Transaction(ctx, func(ctx context.Context) error {...}, otherwise next execution won't happen inside transaction