Skip to content

Commit fb5164f

Browse files
authored
Merge pull request #715 from upper/pgx-v5
upgrade to pgx/v5
2 parents b8d22cf + d51a71a commit fb5164f

File tree

15 files changed

+69
-27
lines changed

15 files changed

+69
-27
lines changed

adapter/cockroachdb/connection_pgx.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ func (c ConnectionURL) String() (s string) {
8181
c.Options["sslmode"] = "prefer"
8282
}
8383

84-
// Disabled by default
85-
c.Options["statement_cache_capacity"] = "0"
84+
c.Options["default_query_exec_mode"] = "cache_describe"
8685

8786
for k, v := range c.Options {
8887
u = append(u, escaper.Replace(k)+"="+escaper.Replace(v))

adapter/cockroachdb/connection_pgx_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,33 @@ func TestConnectionURL(t *testing.T) {
3838

3939
// Adding a host with port.
4040
c.Host = "localhost:1234"
41-
assert.Equal(t, "host=localhost port=1234 sslmode=prefer statement_cache_capacity=0", c.String())
41+
assert.Equal(t, "default_query_exec_mode=cache_describe host=localhost port=1234 sslmode=prefer", c.String())
4242

4343
// Adding a host.
4444
c.Host = "localhost"
45-
assert.Equal(t, "host=localhost port=26257 sslmode=prefer statement_cache_capacity=0", c.String())
45+
assert.Equal(t, "default_query_exec_mode=cache_describe host=localhost port=26257 sslmode=prefer", c.String())
4646

4747
// Adding a username.
4848
c.User = "Anakin"
49-
assert.Equal(t, `host=localhost port=26257 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
49+
assert.Equal(t, `default_query_exec_mode=cache_describe host=localhost port=26257 sslmode=prefer user=Anakin`, c.String())
5050

5151
// Adding a password with special characters.
5252
c.Password = "Some Sort of ' Password"
53-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=26257 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
53+
assert.Equal(t, `default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password port=26257 sslmode=prefer user=Anakin`, c.String())
5454

5555
// Adding a port.
5656
c.Host = "localhost:1234"
57-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
57+
assert.Equal(t, `default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
5858

5959
// Adding a database.
6060
c.Database = "MyDatabase"
61-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
61+
assert.Equal(t, `dbname=MyDatabase default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
6262

6363
// Adding options.
6464
c.Options = map[string]string{
6565
"sslmode": "verify-full",
6666
}
67-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=verify-full statement_cache_capacity=0 user=Anakin`, c.String())
67+
assert.Equal(t, `dbname=MyDatabase default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=verify-full user=Anakin`, c.String())
6868
}
6969

7070
func TestParseConnectionURL(t *testing.T) {

adapter/cockroachdb/database_pgx.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030

3131
"time"
3232

33-
_ "github.com/jackc/pgx/v4/stdlib"
33+
_ "github.com/jackc/pgx/v5/stdlib"
3434
"github.com/upper/db/v4"
3535
"github.com/upper/db/v4/internal/sqladapter"
3636
)
@@ -41,7 +41,11 @@ func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
4141
return nil, err
4242
}
4343
if tz := connURL.Options["timezone"]; tz != "" {
44-
loc, _ := time.LoadLocation(tz)
44+
loc, err := time.LoadLocation(tz)
45+
if err != nil {
46+
return nil, err
47+
}
48+
4549
ctx := context.WithValue(sess.Context(), db.ContextKey("timezone"), loc)
4650
sess.SetContext(ctx)
4751
}

adapter/cockroachdb/database_pq.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
4040
return nil, err
4141
}
4242
if tz := connURL.Options["timezone"]; tz != "" {
43-
loc, _ := time.LoadLocation(tz)
43+
loc, err := time.LoadLocation(tz)
44+
if err != nil {
45+
return nil, err
46+
}
47+
4448
ctx := context.WithValue(sess.Context(), db.ContextKey("timezone"), loc)
4549
sess.SetContext(ctx)
4650
}

adapter/postgresql/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DB_NAME ?= upperio
1111
DB_USERNAME ?= upperio_user
1212
DB_PASSWORD ?= upperio//s3cr37
1313

14-
TEST_FLAGS ?=
14+
TEST_FLAGS ?= -v -failfast
1515
PARALLEL_FLAGS ?= --halt-on-error 2 --jobs 1
1616

1717
export POSTGRES_VERSION

adapter/postgresql/connection.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ func ParseURL(s string) (u *ConnectionURL, err error) {
150150
}
151151

152152
if timezone, ok := u.Options["timezone"]; ok {
153-
u.timezone, _ = time.LoadLocation(timezone)
153+
u.timezone, err = time.LoadLocation(timezone)
154+
if err != nil {
155+
return nil, err
156+
}
154157
}
155158

156159
return u, err

adapter/postgresql/connection_pgx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c ConnectionURL) String() (s string) {
8282
}
8383

8484
// Disabled by default
85-
c.Options["statement_cache_capacity"] = "0"
85+
c.Options["default_query_exec_mode"] = "cache_describe"
8686

8787
for k, v := range c.Options {
8888
u = append(u, escaper.Replace(k)+"="+escaper.Replace(v))

adapter/postgresql/connection_pgx_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,37 +38,36 @@ func TestConnectionURL(t *testing.T) {
3838

3939
// Adding a host with port.
4040
c.Host = "localhost:1234"
41-
assert.Equal(t, "host=localhost port=1234 sslmode=prefer statement_cache_capacity=0", c.String())
41+
assert.Equal(t, "default_query_exec_mode=cache_describe host=localhost port=1234 sslmode=prefer", c.String())
4242

4343
// Adding a host.
4444
c.Host = "localhost"
45-
assert.Equal(t, "host=localhost sslmode=prefer statement_cache_capacity=0", c.String())
45+
assert.Equal(t, "default_query_exec_mode=cache_describe host=localhost sslmode=prefer", c.String())
4646

4747
// Adding a username.
4848
c.User = "Anakin"
49-
assert.Equal(t, `host=localhost sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
49+
assert.Equal(t, `default_query_exec_mode=cache_describe host=localhost sslmode=prefer user=Anakin`, c.String())
5050

5151
// Adding a password with special characters.
5252
c.Password = "Some Sort of ' Password"
53-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
53+
assert.Equal(t, `default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password sslmode=prefer user=Anakin`, c.String())
5454

5555
// Adding a port.
5656
c.Host = "localhost:1234"
57-
assert.Equal(t, `host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
57+
assert.Equal(t, `default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
5858

5959
// Adding a database.
6060
c.Database = "MyDatabase"
61-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer statement_cache_capacity=0 user=Anakin`, c.String())
61+
assert.Equal(t, `dbname=MyDatabase default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=prefer user=Anakin`, c.String())
6262

6363
// Adding options.
6464
c.Options = map[string]string{
6565
"sslmode": "verify-full",
6666
}
67-
assert.Equal(t, `dbname=MyDatabase host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=verify-full statement_cache_capacity=0 user=Anakin`, c.String())
67+
assert.Equal(t, `dbname=MyDatabase default_query_exec_mode=cache_describe host=localhost password=Some\ Sort\ of\ \'\ Password port=1234 sslmode=verify-full user=Anakin`, c.String())
6868
}
6969

7070
func TestParseConnectionURL(t *testing.T) {
71-
7271
{
7372
s := "postgres://anakin:skywalker@localhost/jedis"
7473
u, err := ParseURL(s)

adapter/postgresql/database_pgx.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"database/sql"
3030
"time"
3131

32-
_ "github.com/jackc/pgx/v4/stdlib"
32+
_ "github.com/jackc/pgx/v5/stdlib"
3333
"github.com/upper/db/v4"
3434
"github.com/upper/db/v4/internal/sqladapter"
3535
)
@@ -39,10 +39,16 @@ func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
3939
if err != nil {
4040
return nil, err
4141
}
42+
4243
if tz := connURL.Options["timezone"]; tz != "" {
43-
loc, _ := time.LoadLocation(tz)
44+
loc, err := time.LoadLocation(tz)
45+
if err != nil {
46+
return nil, err
47+
}
48+
4449
ctx := context.WithValue(sess.Context(), db.ContextKey("timezone"), loc)
4550
sess.SetContext(ctx)
4651
}
52+
4753
return sql.Open("pgx", dsn)
4854
}

adapter/postgresql/database_pq.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
4040
return nil, err
4141
}
4242
if tz := connURL.Options["timezone"]; tz != "" {
43-
loc, _ := time.LoadLocation(tz)
43+
loc, err := time.LoadLocation(tz)
44+
if err != nil {
45+
return nil, err
46+
}
47+
4448
ctx := context.WithValue(sess.Context(), db.ContextKey("timezone"), loc)
4549
sess.SetContext(ctx)
4650
}

0 commit comments

Comments
 (0)