ExecuteInTx runs fn inside tx which should already have begun.
(tx driver.Tx, fn func() error)
| 39 | |
| 40 | // ExecuteInTx runs fn inside tx which should already have begun. |
| 41 | func ExecuteInTx(tx driver.Tx, fn func() error) (err error) { |
| 42 | err = fn() |
| 43 | if err == nil { |
| 44 | err = tx.Commit() |
| 45 | if err != nil { |
| 46 | err = errors.Wrapf(err, "exec in tx") |
| 47 | } |
| 48 | } else { |
| 49 | _ = tx.Rollback() |
| 50 | } |
| 51 | return |
| 52 | } |