From 00d123a94473a473c4cb13eb278fdd5b55dc9daa Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 25 Apr 2019 14:25:16 -0500 Subject: [PATCH] Prune methods that delegated to *pgconn.PgConn --- conn.go | 24 ------------------------ conn_test.go | 12 ++---------- pool/conn.go | 2 +- pool/pool_test.go | 22 +++++++++++----------- 4 files changed, 14 insertions(+), 46 deletions(-) diff --git a/conn.go b/conn.go index 363b1b07..af8cf389 100644 --- a/conn.go +++ b/conn.go @@ -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. // diff --git a/conn_test.go b/conn_test.go index 18c48e7c..fa64777f 100644 --- a/conn_test.go +++ b/conn_test.go @@ -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(¤tDB) 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) } diff --git a/pool/conn.go b/pool/conn.go index 68dbc299..273be0aa 100644 --- a/pool/conn.go +++ b/pool/conn.go @@ -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() diff --git a/pool/pool_test.go b/pool/pool_test.go index 649f0cfc..8393c3f9 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -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() }