Documentation
¶
Overview ¶
Package stdtx provides a standardized way to handle database transactions.
Index ¶
- Variables
- func AttemptFromContext(ctx context.Context) int
- func NoTestForMaxQueryPlanCosts(ctx context.Context) bool
- func Transact0[TTx any](ctx context.Context, txr *Transactor[TTx], ...) (err error)
- func Transact1[TTx, U any](ctx context.Context, txr *Transactor[TTx], ...) (res U, err error)
- func WithNoTestForMaxQueryPlanCosts(ctx context.Context) context.Context
- type Driver
- type Transactor
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.
func NoTestForMaxQueryPlanCosts ¶ added in v0.0.122
NoTestForMaxQueryPlanCosts returns whether the cost check is disabled.
func Transact0 ¶
func Transact0[TTx any]( ctx context.Context, txr *Transactor[TTx], fnc func(ctx context.Context, tx TTx) error, ) (err error)
Transact0 runs Transact1 but without a value to return.
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.
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.
Directories
¶
Path | Synopsis |
---|---|
Package stdtxpgxv5 implements the stdtx.Driver for pgx/v5 postgres driver.
|
Package stdtxpgxv5 implements the stdtx.Driver for pgx/v5 postgres driver. |
Package stdtxtest provides testing utilities for our standard transactions.
|
Package stdtxtest provides testing utilities for our standard transactions. |