Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See for configurations: https://golangci-lint.run/usage/configuration/
version: 2

# See: https://golangci-lint.run/usage/formatters/
formatters:
default: none
enable:
- gofmt # https://pkg.go.dev/cmd/gofmt
- gofumpt # https://github.com/mvdan/gofumpt

settings:
gofmt:
simplify: true # Simplify code: gofmt with `-s` option.

gofumpt:
# Module path which contains the source code being formatted.
# Default: ""
module-path: github.com/jackc/pgx/v5 # Should match with module in go.mod
# Choose whether to use the extra rules.
# Default: false
extra-rules: true
2 changes: 0 additions & 2 deletions batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func (br *batchResults) Query() (Rows, error) {
func (br *batchResults) QueryRow() Row {
rows, _ := br.Query()
return (*connRow)(rows.(*baseRows))

}

// Close closes the batch operation. Any error that occurred during a batch operation may have made it impossible to
Expand Down Expand Up @@ -378,7 +377,6 @@ func (br *pipelineBatchResults) Query() (Rows, error) {
func (br *pipelineBatchResults) QueryRow() Row {
rows, _ := br.Query()
return (*connRow)(rows.(*baseRows))

}

// Close closes the batch operation. Any error that occurred during a batch operation may have made it impossible to
Expand Down
16 changes: 0 additions & 16 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

batch := &pgx.Batch{}
batch.Queue("select n from generate_series(0,5) n")
batch.Queue("select n from generate_series(0,5) n")
Expand Down Expand Up @@ -539,7 +538,6 @@ func TestConnSendBatchCloseRowsPartiallyRead(t *testing.T) {
if err != nil {
t.Fatal(err)
}

})
}

Expand All @@ -550,7 +548,6 @@ func TestConnSendBatchQueryError(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

batch := &pgx.Batch{}
batch.Queue("select n from generate_series(0,5) n where 100/(5-n) > 0")
batch.Queue("select n from generate_series(0,5) n")
Expand Down Expand Up @@ -580,7 +577,6 @@ func TestConnSendBatchQueryError(t *testing.T) {
if pgErr, ok := err.(*pgconn.PgError); !(ok && pgErr.Code == "22012") {
t.Errorf("br.Close() => %v, want error code %v", err, 22012)
}

})
}

Expand All @@ -591,7 +587,6 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

batch := &pgx.Batch{}
batch.Queue("select 1 1")

Expand All @@ -607,7 +602,6 @@ func TestConnSendBatchQuerySyntaxError(t *testing.T) {
if err == nil {
t.Error("Expected error")
}

})
}

Expand All @@ -618,7 +612,6 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

sql := `create temporary table ledger(
id serial primary key,
description varchar not null,
Expand Down Expand Up @@ -647,7 +640,6 @@ func TestConnSendBatchQueryRowInsert(t *testing.T) {
}

br.Close()

})
}

Expand All @@ -658,7 +650,6 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

sql := `create temporary table ledger(
id serial primary key,
description varchar not null,
Expand Down Expand Up @@ -687,7 +678,6 @@ func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
}

br.Close()

})
}

Expand All @@ -698,7 +688,6 @@ func TestTxSendBatch(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

sql := `create temporary table ledger1(
id serial primary key,
description varchar not null
Expand Down Expand Up @@ -757,7 +746,6 @@ func TestTxSendBatch(t *testing.T) {
if err != nil {
t.Fatal(err)
}

})
}

Expand All @@ -768,7 +756,6 @@ func TestTxSendBatchRollback(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

sql := `create temporary table ledger1(
id serial primary key,
description varchar not null
Expand All @@ -795,7 +782,6 @@ func TestTxSendBatchRollback(t *testing.T) {
if count != 0 {
t.Errorf("count => %v, want %v", count, 0)
}

})
}

Expand Down Expand Up @@ -855,7 +841,6 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
defer cancel()

pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

pgxtest.SkipCockroachDB(t, conn, "Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")

mustExec(t, conn, `create temporary table t (
Expand Down Expand Up @@ -894,7 +879,6 @@ func TestConnBeginBatchDeferredError(t *testing.T) {
if err, ok := err.(*pgconn.PgError); !ok || err.Code != "23505" {
t.Fatalf("expected error 23505, got %v", err)
}

})
}

Expand Down
18 changes: 12 additions & 6 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,6 @@ func multiInsert(conn *pgx.Conn, tableName string, columnNames []string, rowSrc
}

return rowCount, nil

}

func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
Expand All @@ -535,7 +534,8 @@ func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
src := newBenchmarkWriteTableCopyFromSrc(n)

_, err := multiInsert(conn, "t",
[]string{"varchar_1",
[]string{
"varchar_1",
"varchar_2",
"varchar_null_1",
"date_1",
Expand All @@ -547,7 +547,8 @@ func benchmarkWriteNRowsViaMultiInsert(b *testing.B, n int) {
"tstz_2",
"bool_1",
"bool_2",
"bool_3"},
"bool_3",
},
src)
if err != nil {
b.Fatal(err)
Expand All @@ -568,7 +569,8 @@ func benchmarkWriteNRowsViaCopy(b *testing.B, n int) {

_, err := conn.CopyFrom(context.Background(),
pgx.Identifier{"t"},
[]string{"varchar_1",
[]string{
"varchar_1",
"varchar_2",
"varchar_null_1",
"date_1",
Expand All @@ -580,7 +582,8 @@ func benchmarkWriteNRowsViaCopy(b *testing.B, n int) {
"tstz_2",
"bool_1",
"bool_2",
"bool_3"},
"bool_3",
},
src)
if err != nil {
b.Fatal(err)
Expand Down Expand Up @@ -611,6 +614,7 @@ func BenchmarkWrite5RowsViaInsert(b *testing.B) {
func BenchmarkWrite5RowsViaMultiInsert(b *testing.B) {
benchmarkWriteNRowsViaMultiInsert(b, 5)
}

func BenchmarkWrite5RowsViaBatchInsert(b *testing.B) {
benchmarkWriteNRowsViaBatchInsert(b, 5)
}
Expand All @@ -626,6 +630,7 @@ func BenchmarkWrite10RowsViaInsert(b *testing.B) {
func BenchmarkWrite10RowsViaMultiInsert(b *testing.B) {
benchmarkWriteNRowsViaMultiInsert(b, 10)
}

func BenchmarkWrite10RowsViaBatchInsert(b *testing.B) {
benchmarkWriteNRowsViaBatchInsert(b, 10)
}
Expand All @@ -641,6 +646,7 @@ func BenchmarkWrite100RowsViaInsert(b *testing.B) {
func BenchmarkWrite100RowsViaMultiInsert(b *testing.B) {
benchmarkWriteNRowsViaMultiInsert(b, 100)
}

func BenchmarkWrite100RowsViaBatchInsert(b *testing.B) {
benchmarkWriteNRowsViaBatchInsert(b, 100)
}
Expand Down Expand Up @@ -672,6 +678,7 @@ func BenchmarkWrite10000RowsViaInsert(b *testing.B) {
func BenchmarkWrite10000RowsViaMultiInsert(b *testing.B) {
benchmarkWriteNRowsViaMultiInsert(b, 10000)
}

func BenchmarkWrite10000RowsViaBatchInsert(b *testing.B) {
benchmarkWriteNRowsViaBatchInsert(b, 10000)
}
Expand Down Expand Up @@ -1043,7 +1050,6 @@ func BenchmarkSelectRowsScanDecoder(b *testing.B) {
}
for _, format := range formats {
b.Run(format.name, func(b *testing.B) {

br := &BenchRowDecoder{}
for i := 0; i < b.N; i++ {
rows, err := conn.Query(
Expand Down
5 changes: 2 additions & 3 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ func TestExecPerQuerySimpleProtocol(t *testing.T) {
if commandTag.String() != "INSERT 0 1" {
t.Fatalf("Unexpected results from Exec: %v", commandTag)
}

}

func TestPrepare(t *testing.T) {
Expand Down Expand Up @@ -1089,7 +1088,7 @@ func TestLoadRangeType(t *testing.T) {
conn.TypeMap().RegisterType(newRangeType)
conn.TypeMap().RegisterDefaultPgType(pgtype.Range[float64]{}, "examplefloatrange")

var inputRangeType = pgtype.Range[float64]{
inputRangeType := pgtype.Range[float64]{
Lower: 1.0,
Upper: 2.0,
LowerType: pgtype.Inclusive,
Expand Down Expand Up @@ -1129,7 +1128,7 @@ func TestLoadMultiRangeType(t *testing.T) {
conn.TypeMap().RegisterType(newMultiRangeType)
conn.TypeMap().RegisterDefaultPgType(pgtype.Multirange[pgtype.Range[float64]]{}, "examplefloatmultirange")

var inputMultiRangeType = pgtype.Multirange[pgtype.Range[float64]]{
inputMultiRangeType := pgtype.Multirange[pgtype.Range[float64]]{
{
Lower: 1.0,
Upper: 2.0,
Expand Down
1 change: 0 additions & 1 deletion copy_from_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func TestConnCopyWithAllQueryExecModes(t *testing.T) {
}

func TestConnCopyWithKnownOIDQueryExecModes(t *testing.T) {

for _, mode := range pgxtest.KnownOIDQueryExecModes {
t.Run(mode.String(), func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
Expand Down
1 change: 0 additions & 1 deletion internal/stmtcache/lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func (c *LRUCache) Get(key string) *pgconn.StatementDescription {
}

return nil

}

// Put stores sd in the cache. Put panics if sd.SQL is "". Put does nothing if sd.SQL already exists in the cache or
Expand Down
1 change: 0 additions & 1 deletion pgbouncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ func testPgbouncer(t *testing.T, config *pgx.ConnConfig, workers, iterations int
for i := 0; i < workers; i++ {
<-doneChan
}

}
2 changes: 1 addition & 1 deletion pgconn/auth_scram.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func computeClientProof(saltedPassword, authMessage []byte) []byte {
return buf
}

func computeServerSignature(saltedPassword []byte, authMessage []byte) []byte {
func computeServerSignature(saltedPassword, authMessage []byte) []byte {
serverKey := computeHMAC(saltedPassword, []byte("Server Key"))
serverSignature := computeHMAC(serverKey, authMessage)
buf := make([]byte, base64.StdEncoding.EncodedLen(len(serverSignature)))
Expand Down
4 changes: 0 additions & 4 deletions pgconn/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func BenchmarkExec(b *testing.B) {
}
}
_, err = rr.Close()

if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -127,7 +126,6 @@ func BenchmarkExecPossibleToCancel(b *testing.B) {
}
}
_, err = rr.Close()

if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -184,7 +182,6 @@ func BenchmarkExecPrepared(b *testing.B) {
}
}
_, err = rr.Close()

if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -227,7 +224,6 @@ func BenchmarkExecPreparedPossibleToCancel(b *testing.B) {
}
}
_, err = rr.Close()

if err != nil {
b.Fatal(err)
}
Expand Down
12 changes: 7 additions & 5 deletions pgconn/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (
"github.com/jackc/pgx/v5/pgproto3"
)

type AfterConnectFunc func(ctx context.Context, pgconn *PgConn) error
type ValidateConnectFunc func(ctx context.Context, pgconn *PgConn) error
type GetSSLPasswordFunc func(ctx context.Context) string
type (
AfterConnectFunc func(ctx context.Context, pgconn *PgConn) error
ValidateConnectFunc func(ctx context.Context, pgconn *PgConn) error
GetSSLPasswordFunc func(ctx context.Context) string
)

// Config is the settings used to establish a connection to a PostgreSQL server. It must be created by [ParseConfig]. A
// manually initialized Config will cause ConnectConfig to panic.
Expand Down Expand Up @@ -784,8 +786,8 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
if sslpassword != "" {
decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword))
}
//if sslpassword not provided or has decryption error when use it
//try to find sslpassword with callback function
// if sslpassword not provided or has decryption error when use it
// try to find sslpassword with callback function
if sslpassword == "" || decryptedError != nil {
if parseConfigOptions.GetSSLPassword != nil {
sslpassword = parseConfigOptions.GetSSLPassword(context.Background())
Expand Down
Loading
Loading