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
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# See for configurations: https://golangci-lint.run/usage/configuration/
version: 2

linters:
default: none
enable:
- govet

# See: https://golangci-lint.run/usage/formatters/
formatters:
default: none
Expand Down
2 changes: 1 addition & 1 deletion batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (br *batchResults) nextQueryAndArgs() (query string, args []any, ok bool) {
ok = true
br.qqIdx++
}
return
return query, args, ok
}

type pipelineBatchResults struct {
Expand Down
1 change: 0 additions & 1 deletion batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,6 @@ func TestSendBatchStatementTimeout(t *testing.T) {
_, err = conn.Exec(context.Background(), "Select 1")
assert.NoError(t, err)
})

}

func TestSendBatchHandlesTimeoutBetweenParseAndDescribe(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ func BenchmarkMultipleQueriesNonBatchDescribeStatementCache(b *testing.B) {
}

func benchmarkMultipleQueriesNonBatch(b *testing.B, conn *pgx.Conn, queryCount int) {

for b.Loop() {
for range queryCount {
rows, err := conn.Query(context.Background(), "select n from generate_series(0, 5) n")
Expand Down Expand Up @@ -771,7 +770,6 @@ func BenchmarkMultipleQueriesBatchDescribeStatementCache(b *testing.B) {
}

func benchmarkMultipleQueriesBatch(b *testing.B, conn *pgx.Conn, queryCount int) {

for b.Loop() {
batch := &pgx.Batch{}
for range queryCount {
Expand Down
2 changes: 1 addition & 1 deletion helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func mustExec(t testing.TB, conn *pgx.Conn, sql string, arguments ...any) (comma
if commandTag, err = conn.Exec(context.Background(), sql, arguments...); err != nil {
t.Fatalf("Exec unexpectedly failed with %v: %v", sql, err)
}
return
return commandTag
}

// Do a simple query to ensure the connection is still usable
Expand Down
38 changes: 19 additions & 19 deletions pgtype/bits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,38 @@ func isExpectedEqBits(a any) func(any) bool {
func TestBitsCodecBit(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "bit(40)", []pgxtest.ValueRoundTripTest{
{
pgtype.Bits{Bytes: []byte{0, 0, 0, 0, 0}, Len: 40, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 0, 0, 0, 0}, Len: 40, Valid: true}),
Param: pgtype.Bits{Bytes: []byte{0, 0, 0, 0, 0}, Len: 40, Valid: true},
Result: new(pgtype.Bits),
Test: isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 0, 0, 0, 0}, Len: 40, Valid: true}),
},
{
pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true}),
Param: pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true},
Result: new(pgtype.Bits),
Test: isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true}),
},
{pgtype.Bits{}, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
{nil, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
{Param: pgtype.Bits{}, Result: new(pgtype.Bits), Test: isExpectedEqBits(pgtype.Bits{})},
{Param: nil, Result: new(pgtype.Bits), Test: isExpectedEqBits(pgtype.Bits{})},
})
}

func TestBitsCodecVarbit(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "varbit", []pgxtest.ValueRoundTripTest{
{
pgtype.Bits{Bytes: []byte{}, Len: 0, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{}, Len: 0, Valid: true}),
Param: pgtype.Bits{Bytes: []byte{}, Len: 0, Valid: true},
Result: new(pgtype.Bits),
Test: isExpectedEqBits(pgtype.Bits{Bytes: []byte{}, Len: 0, Valid: true}),
},
{
pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true}),
Param: pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true},
Result: new(pgtype.Bits),
Test: isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true}),
},
{
pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 128}, Len: 33, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 128}, Len: 33, Valid: true}),
Param: pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 128}, Len: 33, Valid: true},
Result: new(pgtype.Bits),
Test: isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 128}, Len: 33, Valid: true}),
},
{pgtype.Bits{}, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
{nil, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
{Param: pgtype.Bits{}, Result: new(pgtype.Bits), Test: isExpectedEqBits(pgtype.Bits{})},
{Param: nil, Result: new(pgtype.Bits), Test: isExpectedEqBits(pgtype.Bits{})},
})
}
10 changes: 5 additions & 5 deletions pgtype/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

func TestBoolCodec(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "bool", []pgxtest.ValueRoundTripTest{
{true, new(bool), isExpectedEq(true)},
{false, new(bool), isExpectedEq(false)},
{true, new(pgtype.Bool), isExpectedEq(pgtype.Bool{Bool: true, Valid: true})},
{pgtype.Bool{}, new(pgtype.Bool), isExpectedEq(pgtype.Bool{})},
{nil, new(*bool), isExpectedEq((*bool)(nil))},
{Param: true, Result: new(bool), Test: isExpectedEq(true)},
{Param: false, Result: new(bool), Test: isExpectedEq(false)},
{Param: true, Result: new(pgtype.Bool), Test: isExpectedEq(pgtype.Bool{Bool: true, Valid: true})},
{Param: pgtype.Bool{}, Result: new(pgtype.Bool), Test: isExpectedEq(pgtype.Bool{})},
{Param: nil, Result: new(*bool), Test: isExpectedEq((*bool)(nil))},
})
}

Expand Down
16 changes: 8 additions & 8 deletions pgtype/box_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ func TestBoxCodec(t *testing.T) {

pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "box", []pgxtest.ValueRoundTripTest{
{
pgtype.Box{
Param: pgtype.Box{
P: [2]pgtype.Vec2{{7.1, 5.2345678}, {3.14, 1.678}},
Valid: true,
},
new(pgtype.Box),
isExpectedEq(pgtype.Box{
Result: new(pgtype.Box),
Test: isExpectedEq(pgtype.Box{
P: [2]pgtype.Vec2{{7.1, 5.2345678}, {3.14, 1.678}},
Valid: true,
}),
},
{
pgtype.Box{
Param: pgtype.Box{
P: [2]pgtype.Vec2{{7.1, 5.2345678}, {-13.14, -5.234}},
Valid: true,
},
new(pgtype.Box),
isExpectedEq(pgtype.Box{
Result: new(pgtype.Box),
Test: isExpectedEq(pgtype.Box{
P: [2]pgtype.Vec2{{7.1, 5.2345678}, {-13.14, -5.234}},
Valid: true,
}),
},
{pgtype.Box{}, new(pgtype.Box), isExpectedEq(pgtype.Box{})},
{nil, new(pgtype.Box), isExpectedEq(pgtype.Box{})},
{Param: pgtype.Box{}, Result: new(pgtype.Box), Test: isExpectedEq(pgtype.Box{})},
{Param: nil, Result: new(pgtype.Box), Test: isExpectedEq(pgtype.Box{})},
})
}
8 changes: 4 additions & 4 deletions pgtype/bytea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ func isExpectedEqBytes(a any) func(any) bool {

func TestByteaCodec(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "bytea", []pgxtest.ValueRoundTripTest{
{[]byte{1, 2, 3}, new([]byte), isExpectedEqBytes([]byte{1, 2, 3})},
{[]byte{}, new([]byte), isExpectedEqBytes([]byte{})},
{[]byte(nil), new([]byte), isExpectedEqBytes([]byte(nil))},
{nil, new([]byte), isExpectedEqBytes([]byte(nil))},
{Param: []byte{1, 2, 3}, Result: new([]byte), Test: isExpectedEqBytes([]byte{1, 2, 3})},
{Param: []byte{}, Result: new([]byte), Test: isExpectedEqBytes([]byte{})},
{Param: []byte(nil), Result: new([]byte), Test: isExpectedEqBytes([]byte(nil))},
{Param: nil, Result: new([]byte), Test: isExpectedEqBytes([]byte(nil))},
})
}

Expand Down
16 changes: 8 additions & 8 deletions pgtype/circle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func TestCircleTranscode(t *testing.T) {

pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "circle", []pgxtest.ValueRoundTripTest{
{
pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true},
new(pgtype.Circle),
isExpectedEq(pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true}),
Param: pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true},
Result: new(pgtype.Circle),
Test: isExpectedEq(pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true}),
},
{
pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true},
new(pgtype.Circle),
isExpectedEq(pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true}),
Param: pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true},
Result: new(pgtype.Circle),
Test: isExpectedEq(pgtype.Circle{P: pgtype.Vec2{1.234, 5.67890123}, R: 3.5, Valid: true}),
},
{pgtype.Circle{}, new(pgtype.Circle), isExpectedEq(pgtype.Circle{})},
{nil, new(pgtype.Circle), isExpectedEq(pgtype.Circle{})},
{Param: pgtype.Circle{}, Result: new(pgtype.Circle), Test: isExpectedEq(pgtype.Circle{})},
{Param: nil, Result: new(pgtype.Circle), Test: isExpectedEq(pgtype.Circle{})},
})
}
30 changes: 15 additions & 15 deletions pgtype/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ func isExpectedEqTime(a any) func(any) bool {

func TestDateCodec(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "date", []pgxtest.ValueRoundTripTest{
{time.Date(-100, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(-100, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(-1, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(-1, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC))},
{time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(2000, 1, 2, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(2000, 1, 2, 0, 0, 0, 0, time.UTC))},
{time.Date(2200, 1, 1, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(2200, 1, 1, 0, 0, 0, 0, time.UTC))},
{time.Date(12200, 1, 2, 0, 0, 0, 0, time.UTC), new(time.Time), isExpectedEqTime(time.Date(12200, 1, 2, 0, 0, 0, 0, time.UTC))},
{pgtype.Date{InfinityModifier: pgtype.Infinity, Valid: true}, new(pgtype.Date), isExpectedEq(pgtype.Date{InfinityModifier: pgtype.Infinity, Valid: true})},
{pgtype.Date{InfinityModifier: pgtype.NegativeInfinity, Valid: true}, new(pgtype.Date), isExpectedEq(pgtype.Date{InfinityModifier: pgtype.NegativeInfinity, Valid: true})},
{pgtype.Date{}, new(pgtype.Date), isExpectedEq(pgtype.Date{})},
{nil, new(*time.Time), isExpectedEq((*time.Time)(nil))},
{Param: time.Date(-100, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(-100, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(-1, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(-1, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(0, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(1999, 12, 31, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(2000, 1, 2, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(2000, 1, 2, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(2200, 1, 1, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(2200, 1, 1, 0, 0, 0, 0, time.UTC))},
{Param: time.Date(12200, 1, 2, 0, 0, 0, 0, time.UTC), Result: new(time.Time), Test: isExpectedEqTime(time.Date(12200, 1, 2, 0, 0, 0, 0, time.UTC))},
{Param: pgtype.Date{InfinityModifier: pgtype.Infinity, Valid: true}, Result: new(pgtype.Date), Test: isExpectedEq(pgtype.Date{InfinityModifier: pgtype.Infinity, Valid: true})},
{Param: pgtype.Date{InfinityModifier: pgtype.NegativeInfinity, Valid: true}, Result: new(pgtype.Date), Test: isExpectedEq(pgtype.Date{InfinityModifier: pgtype.NegativeInfinity, Valid: true})},
{Param: pgtype.Date{}, Result: new(pgtype.Date), Test: isExpectedEq(pgtype.Date{})},
{Param: nil, Result: new(*time.Time), Test: isExpectedEq((*time.Time)(nil))},
})
}

Expand Down
18 changes: 9 additions & 9 deletions pgtype/float4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

func TestFloat4Codec(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "float4", []pgxtest.ValueRoundTripTest{
{pgtype.Float4{Float32: -1, Valid: true}, new(pgtype.Float4), isExpectedEq(pgtype.Float4{Float32: -1, Valid: true})},
{pgtype.Float4{Float32: 0, Valid: true}, new(pgtype.Float4), isExpectedEq(pgtype.Float4{Float32: 0, Valid: true})},
{pgtype.Float4{Float32: 1, Valid: true}, new(pgtype.Float4), isExpectedEq(pgtype.Float4{Float32: 1, Valid: true})},
{float32(0.00001), new(float32), isExpectedEq(float32(0.00001))},
{float32(9999.99), new(float32), isExpectedEq(float32(9999.99))},
{pgtype.Float4{}, new(pgtype.Float4), isExpectedEq(pgtype.Float4{})},
{int64(1), new(int64), isExpectedEq(int64(1))},
{"1.23", new(string), isExpectedEq("1.23")},
{nil, new(*float32), isExpectedEq((*float32)(nil))},
{Param: pgtype.Float4{Float32: -1, Valid: true}, Result: new(pgtype.Float4), Test: isExpectedEq(pgtype.Float4{Float32: -1, Valid: true})},
{Param: pgtype.Float4{Float32: 0, Valid: true}, Result: new(pgtype.Float4), Test: isExpectedEq(pgtype.Float4{Float32: 0, Valid: true})},
{Param: pgtype.Float4{Float32: 1, Valid: true}, Result: new(pgtype.Float4), Test: isExpectedEq(pgtype.Float4{Float32: 1, Valid: true})},
{Param: float32(0.00001), Result: new(float32), Test: isExpectedEq(float32(0.00001))},
{Param: float32(9999.99), Result: new(float32), Test: isExpectedEq(float32(9999.99))},
{Param: pgtype.Float4{}, Result: new(pgtype.Float4), Test: isExpectedEq(pgtype.Float4{})},
{Param: int64(1), Result: new(int64), Test: isExpectedEq(int64(1))},
{Param: "1.23", Result: new(string), Test: isExpectedEq("1.23")},
{Param: nil, Result: new(*float32), Test: isExpectedEq((*float32)(nil))},
})
}

Expand Down
18 changes: 9 additions & 9 deletions pgtype/float8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

func TestFloat8Codec(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "float8", []pgxtest.ValueRoundTripTest{
{pgtype.Float8{Float64: -1, Valid: true}, new(pgtype.Float8), isExpectedEq(pgtype.Float8{Float64: -1, Valid: true})},
{pgtype.Float8{Float64: 0, Valid: true}, new(pgtype.Float8), isExpectedEq(pgtype.Float8{Float64: 0, Valid: true})},
{pgtype.Float8{Float64: 1, Valid: true}, new(pgtype.Float8), isExpectedEq(pgtype.Float8{Float64: 1, Valid: true})},
{float64(0.00001), new(float64), isExpectedEq(float64(0.00001))},
{float64(9999.99), new(float64), isExpectedEq(float64(9999.99))},
{pgtype.Float8{}, new(pgtype.Float8), isExpectedEq(pgtype.Float8{})},
{int64(1), new(int64), isExpectedEq(int64(1))},
{"1.23", new(string), isExpectedEq("1.23")},
{nil, new(*float64), isExpectedEq((*float64)(nil))},
{Param: pgtype.Float8{Float64: -1, Valid: true}, Result: new(pgtype.Float8), Test: isExpectedEq(pgtype.Float8{Float64: -1, Valid: true})},
{Param: pgtype.Float8{Float64: 0, Valid: true}, Result: new(pgtype.Float8), Test: isExpectedEq(pgtype.Float8{Float64: 0, Valid: true})},
{Param: pgtype.Float8{Float64: 1, Valid: true}, Result: new(pgtype.Float8), Test: isExpectedEq(pgtype.Float8{Float64: 1, Valid: true})},
{Param: float64(0.00001), Result: new(float64), Test: isExpectedEq(float64(0.00001))},
{Param: float64(9999.99), Result: new(float64), Test: isExpectedEq(float64(9999.99))},
{Param: pgtype.Float8{}, Result: new(pgtype.Float8), Test: isExpectedEq(pgtype.Float8{})},
{Param: int64(1), Result: new(int64), Test: isExpectedEq(int64(1))},
{Param: "1.23", Result: new(string), Test: isExpectedEq("1.23")},
{Param: nil, Result: new(*float64), Test: isExpectedEq((*float64)(nil))},
})
}

Expand Down
Loading