Prune methods that delegated to *pgconn.PgConn

pull/483/head
Jack Christensen 2019-04-25 14:25:16 -05:00
parent aed6b822d9
commit 00d123a944
4 changed files with 14 additions and 46 deletions

24
conn.go
View File

@ -4,7 +4,6 @@ import (
"context"
"database/sql/driver"
"fmt"
"net"
"reflect"
"strings"
"time"
@ -167,19 +166,6 @@ func connect(ctx context.Context, config *ConnConfig) (c *Conn, err error) {
return c, nil
}
// PID returns the backend PID for this connection.
func (c *Conn) PID() uint32 {
return c.pgConn.PID()
}
// LocalAddr returns the underlying connection's local address
func (c *Conn) LocalAddr() (net.Addr, error) {
if !c.IsAlive() {
return nil, errors.New("connection not ready")
}
return c.pgConn.Conn().LocalAddr(), nil
}
// Close closes a connection. It is safe to call Close on a already closed
// connection.
func (c *Conn) Close(ctx context.Context) error {
@ -195,16 +181,6 @@ func (c *Conn) Close(ctx context.Context) error {
return err
}
func (c *Conn) TxStatus() byte {
return c.pgConn.TxStatus
}
// ParameterStatus returns the value of a parameter reported by the server (e.g.
// server_version). Returns an empty string for unknown parameters.
func (c *Conn) ParameterStatus(key string) string {
return c.pgConn.ParameterStatus(key)
}
// Prepare creates a prepared statement with name and sql. sql can contain placeholders
// for bound parameters. These placeholders are referenced positional as $1, $2, etc.
//

View File

@ -47,14 +47,6 @@ func TestConnect(t *testing.T) {
t.Fatalf("Unable to establish connection: %v", err)
}
if conn.ParameterStatus("server_version") == "" {
t.Error("Runtime parameters not stored")
}
if conn.PID() == 0 {
t.Error("Backend PID not stored")
}
var currentDB string
err = conn.QueryRow(context.Background(), "select current_database()").Scan(&currentDB)
if err != nil {
@ -377,7 +369,7 @@ func TestFatalRxError(t *testing.T) {
otherConn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer otherConn.Close(context.Background())
if _, err := otherConn.Exec(context.Background(), "select pg_terminate_backend($1)", conn.PID()); err != nil {
if _, err := otherConn.Exec(context.Background(), "select pg_terminate_backend($1)", conn.PgConn().PID()); err != nil {
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
}
@ -400,7 +392,7 @@ func TestFatalTxError(t *testing.T) {
otherConn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
defer otherConn.Close(context.Background())
_, err := otherConn.Exec(context.Background(), "select pg_terminate_backend($1)", conn.PID())
_, err := otherConn.Exec(context.Background(), "select pg_terminate_backend($1)", conn.PgConn().PID())
if err != nil {
t.Fatalf("Unable to kill backend PostgreSQL process: %v", err)
}

View File

@ -31,7 +31,7 @@ func (c *Conn) Release() {
return
}
if conn.TxStatus() != 'I' {
if conn.PgConn().TxStatus != 'I' {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_, err := conn.Exec(ctx, "rollback")
cancel()

View File

@ -100,19 +100,19 @@ func TestConnReleaseRollsBackFailedTransaction(t *testing.T) {
c, err := pool.Acquire(ctx)
require.NoError(t, err)
pid := c.Conn().PID()
pid := c.Conn().PgConn().PID()
assert.Equal(t, byte('I'), c.Conn().TxStatus())
assert.Equal(t, byte('I'), c.Conn().PgConn().TxStatus)
_, err = c.Exec(ctx, "begin")
assert.NoError(t, err)
assert.Equal(t, byte('T'), c.Conn().TxStatus())
assert.Equal(t, byte('T'), c.Conn().PgConn().TxStatus)
_, err = c.Exec(ctx, "selct")
assert.Error(t, err)
assert.Equal(t, byte('E'), c.Conn().TxStatus())
assert.Equal(t, byte('E'), c.Conn().PgConn().TxStatus)
c.Release()
waitForReleaseToComplete()
@ -120,8 +120,8 @@ func TestConnReleaseRollsBackFailedTransaction(t *testing.T) {
c, err = pool.Acquire(ctx)
require.NoError(t, err)
assert.Equal(t, pid, c.Conn().PID())
assert.Equal(t, byte('I'), c.Conn().TxStatus())
assert.Equal(t, pid, c.Conn().PgConn().PID())
assert.Equal(t, byte('I'), c.Conn().PgConn().TxStatus)
c.Release()
}
@ -136,14 +136,14 @@ func TestConnReleaseRollsBackInTransaction(t *testing.T) {
c, err := pool.Acquire(ctx)
require.NoError(t, err)
pid := c.Conn().PID()
pid := c.Conn().PgConn().PID()
assert.Equal(t, byte('I'), c.Conn().TxStatus())
assert.Equal(t, byte('I'), c.Conn().PgConn().TxStatus)
_, err = c.Exec(ctx, "begin")
assert.NoError(t, err)
assert.Equal(t, byte('T'), c.Conn().TxStatus())
assert.Equal(t, byte('T'), c.Conn().PgConn().TxStatus)
c.Release()
waitForReleaseToComplete()
@ -151,8 +151,8 @@ func TestConnReleaseRollsBackInTransaction(t *testing.T) {
c, err = pool.Acquire(ctx)
require.NoError(t, err)
assert.Equal(t, pid, c.Conn().PID())
assert.Equal(t, byte('I'), c.Conn().TxStatus())
assert.Equal(t, pid, c.Conn().PgConn().PID())
assert.Equal(t, byte('I'), c.Conn().PgConn().TxStatus)
c.Release()
}