-
Notifications
You must be signed in to change notification settings - Fork 2
/
pg.go
38 lines (30 loc) · 727 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
37
38
package pg
import (
"sync"
"github.com/alexfalkowski/go-service/database/sql/driver"
"github.com/jackc/pgx/v5/stdlib"
"github.com/linxGnu/mssqlx"
"go.opentelemetry.io/otel/trace"
"go.uber.org/fx"
"go.uber.org/zap"
)
// OpenParams for pg.
type OpenParams struct {
fx.In
Lifecycle fx.Lifecycle
Config *Config
}
// Open for pg.
func Open(params OpenParams) (*mssqlx.DBs, error) {
if !IsEnabled(params.Config) {
return &mssqlx.DBs{}, nil
}
return driver.Open(params.Lifecycle, "pg", params.Config.Config)
}
var once sync.Once
// Register the driver for pg.
func Register(tracer trace.Tracer, logger *zap.Logger) {
once.Do(func() {
driver.Register("pg", stdlib.GetDefaultDriver(), tracer, logger)
})
}