kvdb/postgres: fix context cancellation

This commit is contained in:
Joost Jager
2021-12-22 12:33:50 +01:00
parent 62a2f3c809
commit 0cae55c162
5 changed files with 69 additions and 47 deletions

View File

@@ -158,21 +158,11 @@ func (tx *readWriteTx) OnCommit(cb func()) {
}
// QueryRow executes a QueryRow call with a timeout context.
func (tx *readWriteTx) QueryRow(query string, args ...interface{}) *sql.Row {
ctx, cancel := tx.db.getTimeoutCtx()
defer cancel()
return tx.tx.QueryRowContext(ctx, query, args...)
}
// Query executes a Query call with a timeout context.
func (tx *readWriteTx) Query(query string, args ...interface{}) (*sql.Rows,
error) {
func (tx *readWriteTx) QueryRow(query string, args ...interface{}) (*sql.Row,
func()) {
ctx, cancel := tx.db.getTimeoutCtx()
defer cancel()
return tx.tx.QueryContext(ctx, query, args...)
return tx.tx.QueryRowContext(ctx, query, args...), cancel
}
// Exec executes a Exec call with a timeout context.