2
0

Add QueryFunc

refs #821
This commit is contained in:
Jack Christensen
2020-12-12 09:39:58 -06:00
parent 0cbbf55dde
commit e8f959e0e1
7 changed files with 197 additions and 0 deletions
+19
View File
@@ -117,6 +117,7 @@ type Tx interface {
Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)
Query(ctx context.Context, sql string, args ...interface{}) (Rows, error)
QueryRow(ctx context.Context, sql string, args ...interface{}) Row
QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(QueryFuncRow) error) (pgconn.CommandTag, error)
// Conn returns the underlying *Conn that on which this transaction is executing.
Conn() *Conn
@@ -220,6 +221,15 @@ func (tx *dbTx) QueryRow(ctx context.Context, sql string, args ...interface{}) R
return (*connRow)(rows.(*connRows))
}
// QueryFunc delegates to the underlying *Conn.
func (tx *dbTx) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(QueryFuncRow) error) (pgconn.CommandTag, error) {
if tx.closed {
return nil, ErrTxClosed
}
return tx.conn.QueryFunc(ctx, sql, args, scans, f)
}
// CopyFrom delegates to the underlying *Conn
func (tx *dbTx) CopyFrom(ctx context.Context, tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int64, error) {
if tx.closed {
@@ -322,6 +332,15 @@ func (sp *dbSavepoint) QueryRow(ctx context.Context, sql string, args ...interfa
return (*connRow)(rows.(*connRows))
}
// QueryFunc delegates to the underlying Tx.
func (sp *dbSavepoint) QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(QueryFuncRow) error) (pgconn.CommandTag, error) {
if sp.closed {
return nil, ErrTxClosed
}
return sp.tx.QueryFunc(ctx, sql, args, scans, f)
}
// CopyFrom delegates to the underlying *Conn
func (sp *dbSavepoint) CopyFrom(ctx context.Context, tableName Identifier, columnNames []string, rowSrc CopyFromSource) (int64, error) {
if sp.closed {