change code for new version
This commit is contained in:
parent
2e42b0a20a
commit
8abf9ac5ed
|
@ -23,21 +23,19 @@ type Config struct {
|
|||
ConnectionLifetime time.Duration
|
||||
}
|
||||
|
||||
var db *sql.DB
|
||||
|
||||
// Connect ...
|
||||
func Connect(cfg Config, server string) {
|
||||
func Connect(cfg Config, server string) *sql.DB {
|
||||
uri := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s",
|
||||
cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.DBName, cfg.SSLMode)
|
||||
|
||||
// connect
|
||||
c, err := sql.Open("pgx", uri)
|
||||
db, err := sql.Open("pgx", uri)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// ping
|
||||
if err = c.Ping(); err != nil {
|
||||
if err = db.Ping(); err != nil {
|
||||
logger.Error("pgx ping", logger.LogData{
|
||||
Source: "Connect",
|
||||
Message: err.Error(),
|
||||
|
@ -46,9 +44,6 @@ func Connect(cfg Config, server string) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
// assign
|
||||
db = c
|
||||
|
||||
// config
|
||||
if cfg.MaxOpenConnections == 0 {
|
||||
cfg.MaxOpenConnections = 25
|
||||
|
@ -70,9 +65,6 @@ func Connect(cfg Config, server string) {
|
|||
boil.DebugMode = cfg.IsDebug
|
||||
|
||||
fmt.Printf("⚡️[postgres]: connected to %s:%d \n", cfg.Host, cfg.Port)
|
||||
}
|
||||
|
||||
// GetDB ...
|
||||
func GetDB() *sql.DB {
|
||||
return db
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue