mirror of https://github.com/jackc/pgx.git
Expose stdlib.Conn.Conn() to enable database/sql.Conn.Raw()
parent
e6c101413b
commit
2bd26ec7fa
|
@ -257,6 +257,11 @@ type Conn struct {
|
||||||
connConfig pgx.ConnConfig
|
connConfig pgx.ConnConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Conn returns the underlying *pgx.Conn
|
||||||
|
func (c *Conn) Conn() *pgx.Conn {
|
||||||
|
return c.conn
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Conn) Prepare(query string) (driver.Stmt, error) {
|
func (c *Conn) Prepare(query string) (driver.Stmt, error) {
|
||||||
return c.PrepareContext(context.Background(), query)
|
return c.PrepareContext(context.Background(), query)
|
||||||
}
|
}
|
||||||
|
|
|
@ -561,6 +561,21 @@ func TestAcquireConn(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConnRaw(t *testing.T) {
|
||||||
|
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
|
||||||
|
conn, err := db.Conn(context.Background())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var n int
|
||||||
|
err = conn.Raw(func(driverConn interface{}) error {
|
||||||
|
conn := driverConn.(*stdlib.Conn).Conn()
|
||||||
|
return conn.QueryRow(context.Background(), "select 42").Scan(&n)
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 42, n)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// https://github.com/jackc/pgx/issues/673
|
// https://github.com/jackc/pgx/issues/673
|
||||||
func TestReleaseConnWithTxInProgress(t *testing.T) {
|
func TestReleaseConnWithTxInProgress(t *testing.T) {
|
||||||
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
|
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, db *sql.DB) {
|
||||||
|
|
Loading…
Reference in New Issue