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,
)
| 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. |
| 410 | func 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 | |
| 427 | func beginFuncExec(ctx context.Context, tx Tx, fn func(Tx) error) (err error) { |
| 428 | defer func() { |
nothing calls this directly
no test coverage detected