txn

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2022 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPostCommitHook

func AddPostCommitHook(ctx context.Context, hook TxnFunc)

func AddPostCompleteHook

func AddPostCompleteHook(ctx context.Context, hook TxnFunc)

func AddPostRollbackHook

func AddPostRollbackHook(ctx context.Context, hook TxnFunc)

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 WithTxn

func WithTxn(ctx context.Context, m Manager, fn TxnFunc) error

WithTxn executes fn in a transaction. If fn returns an error then the transaction is rolled back. Otherwise it is committed.

Types

type DatabaseProvider

type DatabaseProvider interface {
	WithDatabase(ctx context.Context) (context.Context, error)
}

type Manager

type Manager interface {
	Begin(ctx context.Context) (context.Context, error)
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error

	IsLocked(err error) bool
}

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
}

func (Retryer) WithTxn

func (r Retryer) WithTxn(ctx context.Context, fn TxnFunc) error

type TxnFunc

type TxnFunc func(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL