Skip to content

Commit 29ec6a2

Browse files
Fix: change sql driver for bun
1 parent 8fb3e3f commit 29ec6a2

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

database/bun.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/pkg/errors"
1111
"github.com/uptrace/bun"
1212
"github.com/uptrace/bun/dialect/pgdialect"
13-
"github.com/uptrace/bun/driver/pgdriver"
1413
)
1514

1615
// Bun -
@@ -35,16 +34,26 @@ func (db *Bun) Connect(ctx context.Context, cfg config.Database) error {
3534
return errors.Wrap(ErrUnsupportedDatabaseType, cfg.Kind)
3635
}
3736
if cfg.Path != "" {
38-
db.sqldb = sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(cfg.Path)))
37+
conn, err := sql.Open("postgres", cfg.Path)
38+
if err != nil {
39+
return err
40+
}
41+
db.sqldb = conn
3942
db.conn = bun.NewDB(db.sqldb, pgdialect.New())
4043
} else {
41-
db.sqldb = sql.OpenDB(pgdriver.NewConnector(
42-
pgdriver.WithAddr(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)),
43-
pgdriver.WithDatabase(cfg.Database),
44-
pgdriver.WithPassword(cfg.Password),
45-
pgdriver.WithUser(cfg.User),
46-
pgdriver.WithInsecure(true),
47-
))
44+
connStr := fmt.Sprintf(
45+
"postgres://%s:%s@%s:%d/%s?sslmode=disable",
46+
cfg.User,
47+
cfg.Password,
48+
cfg.Host,
49+
cfg.Port,
50+
cfg.Database,
51+
)
52+
conn, err := sql.Open("postgres", connStr)
53+
if err != nil {
54+
return err
55+
}
56+
db.sqldb = conn
4857
db.conn = bun.NewDB(db.sqldb, pgdialect.New())
4958
}
5059
maxOpenConns := 4 * runtime.GOMAXPROCS(0)

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ require (
2525
github.com/tidwall/gjson v1.16.0
2626
github.com/uptrace/bun v1.1.14
2727
github.com/uptrace/bun/dialect/pgdialect v1.1.14
28-
github.com/uptrace/bun/driver/pgdriver v1.1.14
2928
github.com/yhirose/go-peg v0.0.0-20210804202551-de25d6753cf1
3029
golang.org/x/crypto v0.12.0
3130
golang.org/x/text v0.12.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ github.com/uptrace/bun v1.1.14 h1:S5vvNnjEynJ0CvnrBOD7MIRW7q/WbtvFXrdfy0lddAM=
271271
github.com/uptrace/bun v1.1.14/go.mod h1:RHk6DrIisO62dv10pUOJCz5MphXThuOTpVNYEYv7NI8=
272272
github.com/uptrace/bun/dialect/pgdialect v1.1.14 h1:b7+V1KDJPQSFYgkG/6YLXCl2uvwEY3kf/GSM7hTHRDY=
273273
github.com/uptrace/bun/dialect/pgdialect v1.1.14/go.mod h1:v6YiaXmnKQ2FlhRD2c0ZfKd+QXH09pYn4H8ojaavkKk=
274-
github.com/uptrace/bun/driver/pgdriver v1.1.14 h1:V2Etm7mLGS3mhx8ddxZcUnwZLX02Jmq9JTlo0sNVDhA=
275-
github.com/uptrace/bun/driver/pgdriver v1.1.14/go.mod h1:D4FjWV9arDYct6sjMJhFoyU71SpllZRHXFRRP2Kd0Kw=
276274
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
277275
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
278276
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=

0 commit comments

Comments
 (0)