poolBeginFunc emulates pgx v4's BeginFunc against a *pgxpool.Pool (pgx v5 dropped the helper; we wrote our own).
(ctx context.Context, pool *pgxpool.Pool, fn func(tx pgx.Tx) error)
| 464 | // poolBeginFunc emulates pgx v4's BeginFunc against a *pgxpool.Pool |
| 465 | // (pgx v5 dropped the helper; we wrote our own). |
| 466 | func poolBeginFunc(ctx context.Context, pool *pgxpool.Pool, fn func(tx pgx.Tx) error) error { |
| 467 | tx, err := pool.Begin(ctx) |
| 468 | if err != nil { |
| 469 | return err |
| 470 | } |
| 471 | defer tx.Rollback(ctx) |
| 472 | if err := fn(tx); err != nil { |
| 473 | return err |
| 474 | } |
| 475 | return tx.Commit(ctx) |
| 476 | } |
| 477 | |
| 478 | // Compile guard to remind us we removed the BeginFunc method |
| 479 | // reference above (kept the helper for clarity). |