Properly close rows on empty results
I we don't do this we get "conn busy" errors.
This commit is contained in:
parent
f2585c569c
commit
735a9dc1d2
1 changed files with 12 additions and 4 deletions
|
|
@ -44,14 +44,22 @@ func ExecuteNone(ctx context.Context, stmt postgres.Statement) error {
|
||||||
func ExecuteNoneTx(ctx context.Context, txn Ex, stmt postgres.Statement) error {
|
func ExecuteNoneTx(ctx context.Context, txn Ex, stmt postgres.Statement) error {
|
||||||
query, args := stmt.Sql()
|
query, args := stmt.Sql()
|
||||||
|
|
||||||
_, err := txn.Query(ctx, query, args...)
|
r, err := txn.Query(ctx, query, args...)
|
||||||
return err
|
if err != nil {
|
||||||
|
return fmt.Errorf("query: %w", err)
|
||||||
|
}
|
||||||
|
r.Close()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func ExecuteNoneTxBob(ctx context.Context, txn bob.Tx, stmt postgres.Statement) error {
|
func ExecuteNoneTxBob(ctx context.Context, txn bob.Tx, stmt postgres.Statement) error {
|
||||||
query, args := stmt.Sql()
|
query, args := stmt.Sql()
|
||||||
|
|
||||||
_, err := txn.QueryContext(ctx, query, args...)
|
r, err := txn.QueryContext(ctx, query, args...)
|
||||||
return err
|
if err != nil {
|
||||||
|
return fmt.Errorf("query: %w", err)
|
||||||
|
}
|
||||||
|
r.Close()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
func ExecuteOne[T any](ctx context.Context, stmt postgres.Statement) (T, error) {
|
func ExecuteOne[T any](ctx context.Context, stmt postgres.Statement) (T, error) {
|
||||||
query, args := stmt.Sql()
|
query, args := stmt.Sql()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue