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.
 
 
 
 

33 lines
503 B

package config
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx"
"sync"
)
var dbx *sqlx.DB
var dbLock sync.Mutex
func DBX() *sqlx.DB {
dbLock.Lock()
defer dbLock.Unlock()
if dbx == nil {
dbx = sqlx.MustConnect("mysql", fmt.Sprintf(
"%s:%s@(%s:%d)/%s?parseTime=true",
MySqlUsername(),
MySQlPassword(),
MySqlHost(),
MySqlPort(),
MySqlSchema(),
))
dbx.SetMaxIdleConns(20)
dbx.SetMaxOpenConns(40)
dbx.SetConnMaxLifetime(0)
}
return dbx
}