14 lines
585 B
Go
14 lines
585 B
Go
|
|
package postgres
|
||
|
|
|
||
|
|
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
|
||
|
|
}
|