Commit 480486a6 authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

transaction

parent 40169f67
...@@ -24,6 +24,12 @@ func (d *Pool) TxNew(ctx context.Context) (*Tx, error) { ...@@ -24,6 +24,12 @@ func (d *Pool) TxNew(ctx context.Context) (*Tx, error) {
return &Tx{tx: pgTx, ctx: ctx, pool: d}, err return &Tx{tx: pgTx, ctx: ctx, pool: d}, err
} }
func (d *Pool) TxNewOpts(ctx context.Context, opts pgx.TxOptions) (*Tx, error) {
pgTx, err := d.SrvMaster.BeginTx(ctx, opts)
return &Tx{tx: pgTx, ctx: ctx, pool: d}, err
}
func (d *Pool) MustTx() *Tx { func (d *Pool) MustTx() *Tx {
tx, _ := d.TxNew(d.ctx) tx, _ := d.TxNew(d.ctx)
...@@ -53,7 +59,13 @@ func (t *Tx) Invoke(fn func(*Tx) error) error { ...@@ -53,7 +59,13 @@ func (t *Tx) Invoke(fn func(*Tx) error) error {
return err return err
} }
return t.Commit() if err := t.Commit(); err != nil {
_ = t.Rollback()
return err
}
return nil
} }
func (t *Tx) Get(dst any, sql string, args ...any) error { func (t *Tx) Get(dst any, sql string, args ...any) error {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment