Skip to content

Commit 3b0d447

Browse files
committed
feat: use pgxpool
1 parent c6e49e8 commit 3b0d447

32 files changed

+150
-440
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/gofrs/uuid v4.2.0+incompatible
1212
github.com/golang-migrate/migrate/v4 v4.15.1
1313
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
14+
github.com/jackc/pgconn v1.11.0
1415
github.com/jackc/pgx/v4 v4.15.0
1516
github.com/lithammer/fuzzysearch v1.1.3
1617
github.com/shopspring/decimal v1.3.1
@@ -31,12 +32,12 @@ require (
3132
github.com/hashicorp/errwrap v1.0.0 // indirect
3233
github.com/hashicorp/go-multierror v1.1.0 // indirect
3334
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
34-
github.com/jackc/pgconn v1.11.0 // indirect
3535
github.com/jackc/pgio v1.0.0 // indirect
3636
github.com/jackc/pgpassfile v1.0.0 // indirect
3737
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
3838
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
3939
github.com/jackc/pgtype v1.10.0 // indirect
40+
github.com/jackc/puddle v1.2.1 // indirect
4041
github.com/lib/pq v1.10.2 // indirect
4142
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
4243
github.com/mattn/go-isatty v0.0.14 // indirect

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0f
629629
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
630630
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
631631
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
632+
github.com/jackc/puddle v1.2.1 h1:gI8os0wpRXFd4FiAY2dWiqRK037tjj3t7rKFeO4X5iw=
632633
github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
633634
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
634635
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=

go/cmd/auth/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ go_library(
1717
"//go/pkg/util",
1818
"@com_github_golang_migrate_migrate_v4//source/file",
1919
"@com_github_grpc_ecosystem_go_grpc_middleware//:go-grpc-middleware",
20+
"@com_github_jackc_pgx_v4//pgxpool",
2021
"@com_github_jackc_pgx_v4//stdlib",
2122
"@com_github_urfave_cli_v2//:cli",
2223
"@org_golang_google_grpc//:go_default_library",

go/cmd/auth/migrate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package main
22

33
import (
4-
"database/sql"
54
"fmt"
65

76
authdb "github.com/clstb/phi/go/pkg/auth/db"
87
"github.com/clstb/phi/go/pkg/util"
98
_ "github.com/golang-migrate/migrate/v4/source/file"
9+
"github.com/jackc/pgx/v4/pgxpool"
1010
_ "github.com/jackc/pgx/v4/stdlib"
1111
"github.com/urfave/cli/v2"
1212
)
1313

1414
func Migrate(ctx *cli.Context) error {
15-
db, ok := ctx.Context.Value("db").(*sql.DB)
15+
db, ok := ctx.Context.Value("db").(*pgxpool.Pool)
1616
if !ok {
1717
return fmt.Errorf("missing db")
1818
}

go/cmd/auth/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package main
22

33
import (
4-
"database/sql"
54
"fmt"
65

76
pb "github.com/clstb/phi/go/pkg/auth/pb"
87
"github.com/clstb/phi/go/pkg/auth/server"
98
"github.com/clstb/phi/go/pkg/interceptor"
109
"github.com/clstb/phi/go/pkg/util"
1110
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
11+
"github.com/jackc/pgx/v4/pgxpool"
1212
"github.com/urfave/cli/v2"
1313
"go.uber.org/zap"
1414
"google.golang.org/grpc"
1515
)
1616

1717
func Server(ctx *cli.Context) error {
18-
db, ok := ctx.Context.Value("db").(*sql.DB)
18+
db, ok := ctx.Context.Value("db").(*pgxpool.Pool)
1919
if !ok {
2020
return fmt.Errorf("missing db")
2121
}

go/cmd/tinkgw/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ go_library(
1717
"//go/pkg/util",
1818
"@com_github_golang_migrate_migrate_v4//source/file",
1919
"@com_github_grpc_ecosystem_go_grpc_middleware//:go-grpc-middleware",
20+
"@com_github_jackc_pgx_v4//pgxpool",
2021
"@com_github_jackc_pgx_v4//stdlib",
2122
"@com_github_urfave_cli_v2//:cli",
2223
"@org_golang_google_grpc//:go_default_library",

go/cmd/tinkgw/migrate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package main
22

33
import (
4-
"database/sql"
54
"fmt"
65

76
tinkgwdb "github.com/clstb/phi/go/pkg/tinkgw/db"
87
"github.com/clstb/phi/go/pkg/util"
98
_ "github.com/golang-migrate/migrate/v4/source/file"
9+
"github.com/jackc/pgx/v4/pgxpool"
1010
_ "github.com/jackc/pgx/v4/stdlib"
1111
"github.com/urfave/cli/v2"
1212
)
1313

1414
func Migrate(ctx *cli.Context) error {
15-
db, ok := ctx.Context.Value("db").(*sql.DB)
15+
db, ok := ctx.Context.Value("db").(*pgxpool.Pool)
1616
if !ok {
1717
return fmt.Errorf("missing db")
1818
}

go/cmd/tinkgw/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package main
22

33
import (
4-
"database/sql"
54
"fmt"
65

76
"github.com/clstb/phi/go/pkg/interceptor"
87
pb "github.com/clstb/phi/go/pkg/tinkgw/pb"
98
"github.com/clstb/phi/go/pkg/tinkgw/server"
109
"github.com/clstb/phi/go/pkg/util"
1110
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
11+
"github.com/jackc/pgx/v4/pgxpool"
1212
"github.com/urfave/cli/v2"
1313
"go.uber.org/zap"
1414
"google.golang.org/grpc"
1515
)
1616

1717
func Server(ctx *cli.Context) error {
18-
db, ok := ctx.Context.Value("db").(*sql.DB)
18+
db, ok := ctx.Context.Value("db").(*pgxpool.Pool)
1919
if !ok {
2020
return fmt.Errorf("missing db")
2121
}

go/pkg/auth/db/BUILD.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ go_library(
1515
],
1616
importpath = "github.com/clstb/phi/go/pkg/auth/db",
1717
visibility = ["//visibility:public"],
18-
deps = ["@com_github_gofrs_uuid//:uuid"],
18+
deps = [
19+
"@com_github_gofrs_uuid//:uuid",
20+
"@com_github_jackc_pgconn//:pgconn",
21+
"@com_github_jackc_pgx_v4//:pgx",
22+
],
1923
)

go/pkg/auth/db/db.go

Lines changed: 9 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)