Documentation ¶
Overview ¶
Package txn provides functions for running transactions.
Index ¶
- func AddPostCommitHook(ctx context.Context, hook MustFunc)
- func AddPostCompleteHook(ctx context.Context, hook MustFunc)
- func AddPostRollbackHook(ctx context.Context, hook MustFunc)
- func AddPreCommitHook(ctx context.Context, hook TxnFunc)
- func WithDatabase(ctx context.Context, p DatabaseProvider, fn TxnFunc) error
- func WithReadTxn(ctx context.Context, m Manager, fn TxnFunc) error
- func WithTxn(ctx context.Context, m Manager, fn TxnFunc) error
- type DatabaseProvider
- type Manager
- type MustFunc
- type Retryer
- type TxnFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPostCommitHook ¶
func AddPostCompleteHook ¶
func AddPostRollbackHook ¶
func AddPreCommitHook ¶ added in v0.20.0
func WithDatabase ¶
func WithDatabase(ctx context.Context, p DatabaseProvider, fn TxnFunc) error
WithDatabase executes fn with the context provided by p.WithDatabase. It does not run inside a transaction, so all database operations will be executed in their own transaction.
func WithReadTxn ¶ added in v0.18.0
WithReadTxn executes fn in a transaction. If fn returns an error then the transaction is rolled back. Otherwise it is committed. This function will call m.Begin with writable = false.
Types ¶
type DatabaseProvider ¶
type MustFunc ¶ added in v0.20.0
MustFunc is a function that is used in transaction hooks. It does not return an error.
type Retryer ¶
type Retryer struct { Manager Manager // use value < 0 to retry forever Retries int OnFail func(ctx context.Context, err error, attempt int) error }
Retryer is a provides WithTxn function that retries the transaction if it fails with a locked database error. Transactions are run in exclusive mode.