From 033fc6f62a899f9ee152d3f2b5d06a9df200a8e2 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 30 Jul 2022 09:16:42 -0500 Subject: [PATCH] Rename pgxpool.NewConfig to NewWithConfig https://github.com/jackc/pgx/issues/1264 --- examples/url_shortener/main.go | 2 +- pgxpool/bench_test.go | 4 ++-- pgxpool/pool.go | 6 +++--- pgxpool/pool_test.go | 24 ++++++++++++------------ 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/url_shortener/main.go b/examples/url_shortener/main.go index 092de1fb..12195922 100644 --- a/examples/url_shortener/main.go +++ b/examples/url_shortener/main.go @@ -75,7 +75,7 @@ func main() { log.Fatalln("Unable to parse DATABASE_URL:", err) } - db, err = pgxpool.NewConfig(context.Background(), poolConfig) + db, err = pgxpool.NewWithConfig(context.Background(), poolConfig) if err != nil { log.Fatalln("Unable to create connection pool:", err) } diff --git a/pgxpool/bench_test.go b/pgxpool/bench_test.go index 588d104c..c2d58a38 100644 --- a/pgxpool/bench_test.go +++ b/pgxpool/bench_test.go @@ -34,7 +34,7 @@ func BenchmarkMinimalPreparedSelectBaseline(b *testing.B) { return err } - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(b, err) conn, err := db.Acquire(context.Background()) @@ -65,7 +65,7 @@ func BenchmarkMinimalPreparedSelect(b *testing.B) { return err } - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(b, err) var n int64 diff --git a/pgxpool/pool.go b/pgxpool/pool.go index 9872e670..5fc77014 100644 --- a/pgxpool/pool.go +++ b/pgxpool/pool.go @@ -160,11 +160,11 @@ func New(ctx context.Context, connString string) (*Pool, error) { return nil, err } - return NewConfig(ctx, config) + return NewWithConfig(ctx, config) } -// NewConfig creates a new Pool. config must have been created by ParseConfig. -func NewConfig(ctx context.Context, config *Config) (*Pool, error) { +// NewWithConfig creates a new Pool. config must have been created by ParseConfig. +func NewWithConfig(ctx context.Context, config *Config) (*Pool, error) { // Default values are set in ParseConfig. Enforce initial creation by ParseConfig rather than setting defaults from // zero values. if !config.createdByParseConfig { diff --git a/pgxpool/pool_test.go b/pgxpool/pool_test.go index 0e4d8acf..b5ce9ad7 100644 --- a/pgxpool/pool_test.go +++ b/pgxpool/pool_test.go @@ -30,7 +30,7 @@ func TestConnectConfig(t *testing.T) { connString := os.Getenv("PGX_TEST_DATABASE") config, err := pgxpool.ParseConfig(connString) require.NoError(t, err) - pool, err := pgxpool.NewConfig(context.Background(), config) + pool, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) assertConfigsEqual(t, config, pool.Config(), "Pool.Config() returns original config") pool.Close() @@ -52,7 +52,7 @@ func TestConnectConfigRequiresConnConfigFromParseConfig(t *testing.T) { config := &pgxpool.Config{} - require.PanicsWithValue(t, "config must be created by ParseConfig", func() { pgxpool.NewConfig(context.Background(), config) }) + require.PanicsWithValue(t, "config must be created by ParseConfig", func() { pgxpool.NewWithConfig(context.Background(), config) }) } func TestConfigCopyReturnsEqualConfig(t *testing.T) { @@ -72,7 +72,7 @@ func TestConfigCopyCanBeUsedToConnect(t *testing.T) { copied := original.Copy() assert.NotPanics(t, func() { - _, err = pgxpool.NewConfig(context.Background(), copied) + _, err = pgxpool.NewWithConfig(context.Background(), copied) }) assert.NoError(t, err) } @@ -205,7 +205,7 @@ func TestPoolBeforeConnect(t *testing.T) { return nil } - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -226,7 +226,7 @@ func TestPoolAfterConnect(t *testing.T) { return err } - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -249,7 +249,7 @@ func TestPoolBeforeAcquire(t *testing.T) { return acquireAttempts%2 == 0 } - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -304,7 +304,7 @@ func TestPoolAfterRelease(t *testing.T) { return afterReleaseCount%2 == 1 } - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -357,7 +357,7 @@ func TestConnReleaseChecksMaxConnLifetime(t *testing.T) { config.MaxConnLifetime = 250 * time.Millisecond - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -410,7 +410,7 @@ func TestPoolBackgroundChecksMaxConnLifetime(t *testing.T) { config.MaxConnLifetime = 100 * time.Millisecond config.HealthCheckPeriod = 100 * time.Millisecond - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -435,7 +435,7 @@ func TestPoolBackgroundChecksMaxConnIdleTime(t *testing.T) { config.MaxConnIdleTime = 100 * time.Millisecond config.HealthCheckPeriod = 150 * time.Millisecond - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -464,7 +464,7 @@ func TestPoolBackgroundChecksMinConns(t *testing.T) { config.HealthCheckPeriod = 100 * time.Millisecond config.MinConns = 2 - db, err := pgxpool.NewConfig(context.Background(), config) + db, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer db.Close() @@ -909,7 +909,7 @@ func TestConnectEagerlyReachesMinPoolSize(t *testing.T) { return nil } - pool, err := pgxpool.NewConfig(context.Background(), config) + pool, err := pgxpool.NewWithConfig(context.Background(), config) require.NoError(t, err) defer pool.Close()