mirror of https://github.com/jackc/pgx.git
Add Conn() to Tx interface.
This is necessary to allow code using a Tx to access the *Conn (and pgconn.PgConn) on which the Tx is executing.pull/626/head
parent
c0a1f9976a
commit
143bc3165d
|
@ -1,6 +1,11 @@
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
* Conn.Begin and Conn.BeginTx return a Tx interface instead of the internal dbTx struct. This is necessary for the Conn.Begin method to signature as other methods that begin a transaction. This is technically a breaking change but practically is just a bug fix that is extremely unlikely to break any existing code.
|
## Potentially Breaking Changes
|
||||||
|
|
||||||
|
Technically, two changes are breaking changes, but in practice these are extremely unlikely to break existing code.
|
||||||
|
|
||||||
|
* Conn.Begin and Conn.BeginTx return a Tx interface instead of the internal dbTx struct. This is necessary for the Conn.Begin method to signature as other methods that begin a transaction.
|
||||||
|
* Add Conn() to Tx interface. This is necessary to allow code using a Tx to access the *Conn (and pgconn.PgConn) on which the Tx is executing.
|
||||||
|
|
||||||
# 4.0.1 (September 19, 2019)
|
# 4.0.1 (September 19, 2019)
|
||||||
|
|
||||||
|
|
|
@ -61,3 +61,7 @@ func (tx *Tx) Query(ctx context.Context, sql string, args ...interface{}) (pgx.R
|
||||||
func (tx *Tx) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row {
|
func (tx *Tx) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row {
|
||||||
return tx.t.QueryRow(ctx, sql, args...)
|
return tx.t.QueryRow(ctx, sql, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) Conn() *pgx.Conn {
|
||||||
|
return tx.t.Conn()
|
||||||
|
}
|
||||||
|
|
11
tx.go
11
tx.go
|
@ -111,6 +111,9 @@ type Tx interface {
|
||||||
Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)
|
Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error)
|
||||||
Query(ctx context.Context, sql string, args ...interface{}) (Rows, error)
|
Query(ctx context.Context, sql string, args ...interface{}) (Rows, error)
|
||||||
QueryRow(ctx context.Context, sql string, args ...interface{}) Row
|
QueryRow(ctx context.Context, sql string, args ...interface{}) Row
|
||||||
|
|
||||||
|
// Conn returns the underlying *Conn that on which this transaction is executing.
|
||||||
|
Conn() *Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
// dbTx represents a database transaction.
|
// dbTx represents a database transaction.
|
||||||
|
@ -234,6 +237,10 @@ func (tx *dbTx) LargeObjects() LargeObjects {
|
||||||
return LargeObjects{tx: tx}
|
return LargeObjects{tx: tx}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tx *dbTx) Conn() *Conn {
|
||||||
|
return tx.conn
|
||||||
|
}
|
||||||
|
|
||||||
// dbSavepoint represents a nested transaction implemented by a savepoint.
|
// dbSavepoint represents a nested transaction implemented by a savepoint.
|
||||||
type dbSavepoint struct {
|
type dbSavepoint struct {
|
||||||
tx Tx
|
tx Tx
|
||||||
|
@ -330,3 +337,7 @@ func (sp *dbSavepoint) SendBatch(ctx context.Context, b *Batch) BatchResults {
|
||||||
func (sp *dbSavepoint) LargeObjects() LargeObjects {
|
func (sp *dbSavepoint) LargeObjects() LargeObjects {
|
||||||
return LargeObjects{tx: sp}
|
return LargeObjects{tx: sp}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sp *dbSavepoint) Conn() *Conn {
|
||||||
|
return sp.tx.Conn()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue