Documentation
¶
Overview ¶
Package stdtx provides a standardized way to handle database transactions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyInTransactionScope = errors.New("attempt to transact while transaction was already detected")
ErrAlreadyInTransactionScope is returned when transacting has detected that somewhere up the context call chain a transaction was already started.
Functions ¶
func AttemptFromContext ¶
AttemptFromContext returns which execution attempt it is. Panics if this information is not present.
Types ¶
type Driver ¶
type Driver[TTx any] interface { BeginTx(ctx context.Context) (TTx, error) RollbackTx(ctx context.Context, tx TTx) error CommitTx(ctx context.Context, tx TTx) error SerializationFailureCodes() []string SerializationFailureMaxRetries() int TxDoneError() error }
Driver abstracts the sql implementation details for the transactor to function.
func NewPgxV5Driver ¶
NewPgxV5Driver implements the driver for pgx v5.
type Transactor ¶
type Transactor[TTX any] struct { // contains filtered or unexported fields }
Transactor provides transactions. It can be passed to Transact0 and Transact1 to eaily run code transactionally. A driver can be implemented to support different postgres libraries.
func NewTransactor ¶
func NewTransactor[TTX any](drv Driver[TTX]) *Transactor[TTX]
NewTransactor inits a transactor given the driver.