MCPcopy
hub / github.com/jackc/pgx / BeginTxFunc

Function BeginTxFunc

tx.go:410–425  ·  view source on GitHub ↗

BeginTxFunc calls BeginTx on db and then calls fn. If fn does not return an error then it calls [Tx.Commit] on db. If fn returns an error it calls [Tx.Rollback] on db. The context will be used when executing the transaction control statements (BEGIN, ROLLBACK, and COMMIT) but does not otherwise affe

(
	ctx context.Context,
	db interface {
		BeginTx(ctx context.Context, txOptions TxOptions) (Tx, error)
	},
	txOptions TxOptions,
	fn func(Tx) error,
)

Source from the content-addressed store, hash-verified

408// returns an error it calls [Tx.Rollback] on db. The context will be used when executing the transaction control statements
409// (BEGIN, ROLLBACK, and COMMIT) but does not otherwise affect the execution of fn.
410func BeginTxFunc(
411 ctx context.Context,
412 db interface {
413 BeginTx(ctx context.Context, txOptions TxOptions) (Tx, error)
414 },
415 txOptions TxOptions,
416 fn func(Tx) error,
417) (err error) {
418 var tx Tx
419 tx, err = db.BeginTx(ctx, txOptions)
420 if err != nil {
421 return err
422 }
423
424 return beginFuncExec(ctx, tx, fn)
425}
426
427func beginFuncExec(ctx context.Context, tx Tx, fn func(Tx) error) (err error) {
428 defer func() {

Callers

nothing calls this directly

Calls 2

beginFuncExecFunction · 0.85
BeginTxMethod · 0.45

Tested by

no test coverage detected