feat: 0.0.1
This commit is contained in:
146 files changed
+10444
No files matched your search
@@ -0,0 +1,24 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// execTx executes a function within a database transaction
|
||||
func (store *PostgresStore) execTx(ctx context.Context, fn func(*Queries) error) error {
|
||||
tx, err := store.connPool.Begin(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
q := New(tx)
|
||||
|
||||
err = fn(q)
|
||||
if err != nil {
|
||||
if rbErr := tx.Rollback(ctx); rbErr != nil {
|
||||
return fmt.Errorf("tx err: %v, rb err: %v", err, rbErr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return tx.Commit(ctx)
|
||||
}
|
||||
Reference in new issue
Block a user