Skip to content

Commit

Permalink
fix: wrap builder
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Aug 1, 2024
1 parent 31d6917 commit 9162b43
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions dbx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ func (d *databaseImpl[R, W]) ReadWriteTx(ctx context.Context, fn func(context.Co
return err
}

if err := fn(ctx, rwtx); err != nil {
err = fn(ctx, rwtx)
if err != nil {
tx.Rollback()
return NewQueryError("rollback transaction", err)
}

if err := tx.Commit().Error; err != nil && !errors.Is(err, sql.ErrTxDone) {
Expand All @@ -118,15 +120,12 @@ func (d *databaseImpl[R, W]) ReadTx(ctx context.Context, fn func(context.Context
err = fn(ctx, rtx)
if err != nil {
tx.Rollback()
return NewQueryError("rollback transaction", err)
}

if err := tx.Commit().Error; err != nil && !errors.Is(err, sql.ErrTxDone) {
return NewQueryError("commit read transaction", err)
}

if err != nil {
return NewQueryError("commit read transaction", err)
}

return nil
}

0 comments on commit 9162b43

Please sign in to comment.