Documentation ¶
Index ¶
- Variables
- func CurrentTx(ctx context.Context) (*sqlx.Tx, error)
- func New(ctx context.Context, getdb func(context.Context) (*sqlx.DB, error)) (context.Context, finishFunc)
- func NewWithTransaction(ctx context.Context, tx *sqlx.Tx) context.Context
- func WrapCallsInTransactions(getdb func(context.Context) (*sqlx.DB, error)) func(api.RoutableFunc) api.RoutableFunc
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func New ¶
func New(ctx context.Context, getdb func(context.Context) (*sqlx.DB, error)) (context.Context, finishFunc)
New returns a new child context that can be used with CurrentTx(). It does not open a database transaction until the first call to CurrentTx().
The caller must eventually call the returned finishtx() func to commit or rollback the transaction, if any.
func example(ctx context.Context) (err error) { ctx, finishtx := New(ctx, dber) defer finishtx(&err) // ... tx, err := CurrentTx(ctx) if err != nil { return fmt.Errorf("example: %s", err) } return tx.ExecContext(...) }
If *err is nil, finishtx() commits the transaction and assigns any resulting error to *err.
If *err is non-nil, finishtx() rolls back the transaction, and does not modify *err.
func NewWithTransaction ¶
NewWithTransaction returns a child context in which the given transaction will be used by any localdb API call that needs one. The caller is responsible for calling Commit or Rollback on tx.
func WrapCallsInTransactions ¶
func WrapCallsInTransactions(getdb func(context.Context) (*sqlx.DB, error)) func(api.RoutableFunc) api.RoutableFunc
WrapCallsInTransactions returns a call wrapper (suitable for assigning to router.router.WrapCalls) that starts a new transaction for each API call, and commits only if the call succeeds.
The wrapper calls getdb() to get a database handle before each API call.
Types ¶
This section is empty.