Commit 68ffbd0d by 朱继来

调整db

parent b0188ed3
......@@ -35,7 +35,7 @@ func main() {
tm := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
yesterday_time := tm.AddDate(0, 0, -1).Unix()
db := dao.GetLiexinDb()
db := dao.GetLiexinOrderDb()
row, err := db.Queryx("SELECT user_id, FROM_UNIXTIME(create_time, \"%Y%m%d\") AS date, COUNT(*) AS count FROM `lie_order` " +
"WHERE user_id > 0 AND is_type = 0 AND create_time > ? GROUP BY user_id, date ORDER BY create_time", yesterday_time)
defer db.Close()
......
......@@ -11,11 +11,13 @@ import (
var instance * sqlx.DB
var instanceCms * sqlx.DB
var instanceLiexin * sqlx.DB
var instanceLiexinOrder * sqlx.DB
var instanceLiexinBom * sqlx.DB
var once sync.Once
var onceCms sync.Once
var onceLiexin sync.Once
var onceLiexinOrder sync.Once
var onceLiexinBom sync.Once
// 创建可释放的db连接
......@@ -64,6 +66,15 @@ func GetLiexinDb()(*sqlx.DB) {
return instanceLiexin
}
func GetLiexinOrderDb()(*sqlx.DB) {
dbConfig := configs.GetDBLiexinOrder()
db, err := sqlx.Open(dbConfig.Engine, fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbConfig.User, dbConfig.Pass, dbConfig.Ip, dbConfig.Port, dbConfig.Table))
if err != nil {
log.Fatalln(err)
}
return db
}
func GetLiexinBomDb()(*sqlx.DB) {
onceLiexinBom.Do(func() {
dbConfig := configs.GetDBLiexinBom()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment