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.
 
 
 
 

29 lines
422 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(),
))
}
return dbx
}