-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
36 lines (32 loc) · 781 Bytes
/
init.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 x
import (
"context"
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/michaelzx/pgx-z/pgxz"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"os"
)
var db *pgxz.PgDb
var gormdb *gorm.DB
func init() {
connStr := "postgresql://postgres:postgres@127.0.0.1:5432/cirs_gws?"
pool, err := pgxpool.New(context.TODO(), connStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to create connection pool: %v\n", err)
os.Exit(1)
}
db = pgxz.New(pool)
db.Ping(context.TODO())
// https://github.com/go-gorm/postgres
gormdb, err = gorm.Open(postgres.New(postgres.Config{
DSN: connStr,
PreferSimpleProtocol: true, // disables implicit prepared statement usage
}), &gorm.Config{})
gd, err := gormdb.DB()
if err != nil {
panic(err)
}
gd.Ping()
}