mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
537 B
30 lines
537 B
2 years ago
|
// Copyright 2023 ROC. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package conf
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"sync"
|
||
|
|
||
|
"github.com/jackc/pgx/v5"
|
||
|
"github.com/sirupsen/logrus"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
_pgxDB *pgx.Conn
|
||
|
_oncePgx sync.Once
|
||
|
)
|
||
|
|
||
|
func MustPgxDB() *pgx.Conn {
|
||
|
_oncePgx.Do(func() {
|
||
|
conn, err := pgx.Connect(context.Background(), PostgresSetting.Dsn())
|
||
|
if err != nil {
|
||
|
logrus.Fatalf("pgx.Connect occurs error: %s", err)
|
||
|
}
|
||
|
_pgxDB = conn
|
||
|
})
|
||
|
return _pgxDB
|
||
|
}
|