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

Function beginFuncExec

tx.go:427–442  ·  view source on GitHub ↗
(ctx context.Context, tx Tx, fn func(Tx) error)

Source from the content-addressed store, hash-verified

425}
426
427func beginFuncExec(ctx context.Context, tx Tx, fn func(Tx) error) (err error) {
428 defer func() {
429 rollbackErr := tx.Rollback(ctx)
430 if rollbackErr != nil && !errors.Is(rollbackErr, ErrTxClosed) {
431 err = rollbackErr
432 }
433 }()
434
435 fErr := fn(tx)
436 if fErr != nil {
437 _ = tx.Rollback(ctx) // ignore rollback error as there is already an error to return
438 return fErr
439 }
440
441 return tx.Commit(ctx)
442}

Callers 2

BeginFuncFunction · 0.85
BeginTxFuncFunction · 0.85

Calls 2

RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected