-
Notifications
You must be signed in to change notification settings - Fork 3
/
pg.go
36 lines (29 loc) · 816 Bytes
/
pg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package pg
import (
"sync"
"github.com/alexfalkowski/go-service/database/sql/driver"
"github.com/alexfalkowski/go-service/database/sql/pg/trace/opentracing"
"github.com/alexfalkowski/go-service/version"
"github.com/jackc/pgx/v4/stdlib"
"github.com/linxGnu/mssqlx"
"go.uber.org/fx"
"go.uber.org/zap"
)
// DBParams for PostgreSQL.
type DBParams struct {
fx.In
Lifecycle fx.Lifecycle
Config *Config
Version version.Version
}
// Open for PostgreSQL.
func Open(params DBParams) (*mssqlx.DBs, error) {
return driver.Open(params.Lifecycle, "pg", params.Config.Config, params.Version)
}
var once sync.Once
// Register the driver for PostgreSQL.
func Register(tracer opentracing.Tracer, logger *zap.Logger) {
once.Do(func() {
driver.Register("pg", stdlib.GetDefaultDriver(), tracer, logger)
})
}