Files
db-mysql/unit_of_work.go
T

14 lines
582 B
Go
Raw Normal View History

package mysql
import "context"
// UnitOfWork wraps a set of repository operations in a single database transaction.
// The transaction is injected into the context; [Provider.GetExecutor] returns it
// automatically so repository code requires no changes to participate.
type UnitOfWork interface {
// Do begins a transaction, calls fn with the enriched context, and commits
// on success or rolls back on error. The original fn error is always returned
// when fn fails, regardless of the rollback outcome.
Do(ctx context.Context, fn func(ctx context.Context) error) error
}