Documentation ¶
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. Transaction is not exclusive and does not enforce read-only restrictions. Multiple threads can run transactions using this function concurrently, but concurrent writes may result in locked database error.
func WithTxn ¶
WithTxn executes fn in a transaction. If fn returns an error then the transaction is rolled back. Otherwise it is committed. Transaction is exclusive. Only one thread may run a transaction using this function at a time. This function will wait until the lock is available before executing. This function should be used for making changes to the database.
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.