Make getSharedConnection private again

pgx-vs-pq
Jack Christensen 2013-07-16 08:32:49 -05:00
parent bae49077ce
commit 9640dc91e4
5 changed files with 32 additions and 32 deletions

View File

@ -63,7 +63,7 @@ func restoreBinaryEncoders(encoders map[pgx.Oid]func(*pgx.MessageReader, int32)
} }
func BenchmarkSelectRowSimpleNarrow(b *testing.B) { func BenchmarkSelectRowSimpleNarrow(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createNarrowTestData(b, conn) createNarrowTestData(b, conn)
// Get random ids outside of timing // Get random ids outside of timing
@ -79,7 +79,7 @@ func BenchmarkSelectRowSimpleNarrow(b *testing.B) {
} }
func BenchmarkSelectRowPreparedNarrow(b *testing.B) { func BenchmarkSelectRowPreparedNarrow(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createNarrowTestData(b, conn) createNarrowTestData(b, conn)
// Get random ids outside of timing // Get random ids outside of timing
@ -95,7 +95,7 @@ func BenchmarkSelectRowPreparedNarrow(b *testing.B) {
} }
func BenchmarkSelectRowsSimpleNarrow(b *testing.B) { func BenchmarkSelectRowsSimpleNarrow(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createNarrowTestData(b, conn) createNarrowTestData(b, conn)
// Get random ids outside of timing // Get random ids outside of timing
@ -111,7 +111,7 @@ func BenchmarkSelectRowsSimpleNarrow(b *testing.B) {
} }
func BenchmarkSelectRowsPreparedNarrow(b *testing.B) { func BenchmarkSelectRowsPreparedNarrow(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createNarrowTestData(b, conn) createNarrowTestData(b, conn)
// Get random ids outside of timing // Get random ids outside of timing
@ -198,7 +198,7 @@ func createJoinsTestData(b *testing.B, conn *pgx.Connection) {
} }
func BenchmarkSelectRowsSimpleJoins(b *testing.B) { func BenchmarkSelectRowsSimpleJoins(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createJoinsTestData(b, conn) createJoinsTestData(b, conn)
sql := ` sql := `
@ -218,7 +218,7 @@ func BenchmarkSelectRowsSimpleJoins(b *testing.B) {
} }
func BenchmarkSelectRowsPreparedJoins(b *testing.B) { func BenchmarkSelectRowsPreparedJoins(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createJoinsTestData(b, conn) createJoinsTestData(b, conn)
b.ResetTimer() b.ResetTimer()
@ -253,7 +253,7 @@ func createInt2TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
} }
func BenchmarkInt2Text(b *testing.B) { func BenchmarkInt2Text(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createInt2TextVsBinaryTestData(b, conn) createInt2TextVsBinaryTestData(b, conn)
encoders := removeBinaryEncoders() encoders := removeBinaryEncoders()
@ -269,7 +269,7 @@ func BenchmarkInt2Text(b *testing.B) {
} }
func BenchmarkInt2Binary(b *testing.B) { func BenchmarkInt2Binary(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createInt2TextVsBinaryTestData(b, conn) createInt2TextVsBinaryTestData(b, conn)
mustPrepare(b, conn, "selectInt16", "select * from t") mustPrepare(b, conn, "selectInt16", "select * from t")
defer func() { conn.Deallocate("selectInt16") }() defer func() { conn.Deallocate("selectInt16") }()
@ -306,7 +306,7 @@ func createInt4TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
} }
func BenchmarkInt4Text(b *testing.B) { func BenchmarkInt4Text(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createInt4TextVsBinaryTestData(b, conn) createInt4TextVsBinaryTestData(b, conn)
encoders := removeBinaryEncoders() encoders := removeBinaryEncoders()
@ -322,7 +322,7 @@ func BenchmarkInt4Text(b *testing.B) {
} }
func BenchmarkInt4Binary(b *testing.B) { func BenchmarkInt4Binary(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createInt4TextVsBinaryTestData(b, conn) createInt4TextVsBinaryTestData(b, conn)
mustPrepare(b, conn, "selectInt32", "select * from t") mustPrepare(b, conn, "selectInt32", "select * from t")
defer func() { conn.Deallocate("selectInt32") }() defer func() { conn.Deallocate("selectInt32") }()
@ -359,7 +359,7 @@ func createInt8TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
} }
func BenchmarkInt8Text(b *testing.B) { func BenchmarkInt8Text(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createInt8TextVsBinaryTestData(b, conn) createInt8TextVsBinaryTestData(b, conn)
encoders := removeBinaryEncoders() encoders := removeBinaryEncoders()
@ -375,7 +375,7 @@ func BenchmarkInt8Text(b *testing.B) {
} }
func BenchmarkInt8Binary(b *testing.B) { func BenchmarkInt8Binary(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createInt8TextVsBinaryTestData(b, conn) createInt8TextVsBinaryTestData(b, conn)
mustPrepare(b, conn, "selectInt64", "select * from t") mustPrepare(b, conn, "selectInt64", "select * from t")
defer func() { conn.Deallocate("selectInt64") }() defer func() { conn.Deallocate("selectInt64") }()
@ -412,7 +412,7 @@ func createFloat4TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
} }
func BenchmarkFloat4Text(b *testing.B) { func BenchmarkFloat4Text(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createFloat4TextVsBinaryTestData(b, conn) createFloat4TextVsBinaryTestData(b, conn)
encoders := removeBinaryEncoders() encoders := removeBinaryEncoders()
@ -428,7 +428,7 @@ func BenchmarkFloat4Text(b *testing.B) {
} }
func BenchmarkFloat4Binary(b *testing.B) { func BenchmarkFloat4Binary(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createFloat4TextVsBinaryTestData(b, conn) createFloat4TextVsBinaryTestData(b, conn)
mustPrepare(b, conn, "selectFloat32", "select * from t") mustPrepare(b, conn, "selectFloat32", "select * from t")
defer func() { conn.Deallocate("selectFloat32") }() defer func() { conn.Deallocate("selectFloat32") }()
@ -465,7 +465,7 @@ func createFloat8TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
} }
func BenchmarkFloat8Text(b *testing.B) { func BenchmarkFloat8Text(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createFloat8TextVsBinaryTestData(b, conn) createFloat8TextVsBinaryTestData(b, conn)
encoders := removeBinaryEncoders() encoders := removeBinaryEncoders()
@ -481,7 +481,7 @@ func BenchmarkFloat8Text(b *testing.B) {
} }
func BenchmarkFloat8Binary(b *testing.B) { func BenchmarkFloat8Binary(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createFloat8TextVsBinaryTestData(b, conn) createFloat8TextVsBinaryTestData(b, conn)
mustPrepare(b, conn, "selectFloat32", "select * from t") mustPrepare(b, conn, "selectFloat32", "select * from t")
defer func() { conn.Deallocate("selectFloat32") }() defer func() { conn.Deallocate("selectFloat32") }()
@ -518,7 +518,7 @@ func createBoolTextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
} }
func BenchmarkBoolText(b *testing.B) { func BenchmarkBoolText(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createBoolTextVsBinaryTestData(b, conn) createBoolTextVsBinaryTestData(b, conn)
encoders := removeBinaryEncoders() encoders := removeBinaryEncoders()
@ -534,7 +534,7 @@ func BenchmarkBoolText(b *testing.B) {
} }
func BenchmarkBoolBinary(b *testing.B) { func BenchmarkBoolBinary(b *testing.B) {
conn := GetSharedConnection() conn := getSharedConnection()
createBoolTextVsBinaryTestData(b, conn) createBoolTextVsBinaryTestData(b, conn)
mustPrepare(b, conn, "selectBool", "select * from t") mustPrepare(b, conn, "selectBool", "select * from t")
defer func() { conn.Deallocate("selectBool") }() defer func() { conn.Deallocate("selectBool") }()

View File

@ -121,7 +121,7 @@ func TestConnectWithMD5Password(t *testing.T) {
} }
func TestExecute(t *testing.T) { func TestExecute(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
if results := mustExecute(t, conn, "create temporary table foo(id integer primary key);"); results != "CREATE TABLE" { if results := mustExecute(t, conn, "create temporary table foo(id integer primary key);"); results != "CREATE TABLE" {
t.Error("Unexpected results from Execute") t.Error("Unexpected results from Execute")
@ -164,7 +164,7 @@ func TestExecuteFailure(t *testing.T) {
} }
func TestSelectFunc(t *testing.T) { func TestSelectFunc(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
var sum, rowCount int32 var sum, rowCount int32
onDataRow := func(r *pgx.DataRowReader) error { onDataRow := func(r *pgx.DataRowReader) error {
@ -203,7 +203,7 @@ func TestSelectFuncFailure(t *testing.T) {
} }
func TestSelectRows(t *testing.T) { func TestSelectRows(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
rows := mustSelectRows(t, conn, "select $1 as name, null as position", "Jack") rows := mustSelectRows(t, conn, "select $1 as name, null as position", "Jack")
@ -225,7 +225,7 @@ func TestSelectRows(t *testing.T) {
} }
func TestSelectRow(t *testing.T) { func TestSelectRow(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
row := mustSelectRow(t, conn, "select $1 as name, null as position", "Jack") row := mustSelectRow(t, conn, "select $1 as name, null as position", "Jack")
if row["name"] != "Jack" { if row["name"] != "Jack" {
@ -252,7 +252,7 @@ func TestSelectRow(t *testing.T) {
} }
func TestConnectionSelectValue(t *testing.T) { func TestConnectionSelectValue(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
test := func(sql string, expected interface{}, arguments ...interface{}) { test := func(sql string, expected interface{}, arguments ...interface{}) {
v, err := conn.SelectValue(sql, arguments...) v, err := conn.SelectValue(sql, arguments...)
@ -292,7 +292,7 @@ func TestConnectionSelectValue(t *testing.T) {
} }
func TestSelectValues(t *testing.T) { func TestSelectValues(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
test := func(sql string, expected []interface{}, arguments ...interface{}) { test := func(sql string, expected []interface{}, arguments ...interface{}) {
values, err := conn.SelectValues(sql, arguments...) values, err := conn.SelectValues(sql, arguments...)

View File

@ -6,7 +6,7 @@ import (
) )
func TestDataRowReaderReadValue(t *testing.T) { func TestDataRowReaderReadValue(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
test := func(sql string, expected interface{}) { test := func(sql string, expected interface{}) {
var v interface{} var v interface{}

View File

@ -8,18 +8,18 @@ type test interface {
Fatalf(format string, args ...interface{}) Fatalf(format string, args ...interface{})
} }
var SharedConnection *pgx.Connection var sharedConnection *pgx.Connection
func GetSharedConnection() (c *pgx.Connection) { func getSharedConnection() (c *pgx.Connection) {
if SharedConnection == nil { if sharedConnection == nil {
var err error var err error
SharedConnection, err = pgx.Connect(*defaultConnectionParameters) sharedConnection, err = pgx.Connect(*defaultConnectionParameters)
if err != nil { if err != nil {
panic("Unable to establish connection") panic("Unable to establish connection")
} }
} }
return SharedConnection return sharedConnection
} }
func mustPrepare(t test, conn *pgx.Connection, name, sql string) { func mustPrepare(t test, conn *pgx.Connection, name, sql string) {

View File

@ -5,7 +5,7 @@ import (
) )
func TestQuoteString(t *testing.T) { func TestQuoteString(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
if conn.QuoteString("test") != "'test'" { if conn.QuoteString("test") != "'test'" {
t.Error("Failed to quote string") t.Error("Failed to quote string")
@ -17,7 +17,7 @@ func TestQuoteString(t *testing.T) {
} }
func TestSanitizeSql(t *testing.T) { func TestSanitizeSql(t *testing.T) {
conn := GetSharedConnection() conn := getSharedConnection()
if conn.SanitizeSql("select $1", "Jack's") != "select 'Jack''s'" { if conn.SanitizeSql("select $1", "Jack's") != "select 'Jack''s'" {
t.Error("Failed to sanitize string") t.Error("Failed to sanitize string")