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.
22 lines
552 B
22 lines
552 B
package qmsql
|
|
|
|
import (
|
|
"github.com/jinzhu/gorm"
|
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
|
"log"
|
|
"main/config"
|
|
)
|
|
|
|
var DEFAULTDB *gorm.DB
|
|
|
|
//初始化数据库并产生数据库全局变量
|
|
func InitMysql(admin config.Admin) *gorm.DB {
|
|
if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
|
|
log.Printf("DEFAULTDB数据库启动异常%S", err)
|
|
} else {
|
|
DEFAULTDB = db
|
|
DEFAULTDB.DB().SetMaxIdleConns(10)
|
|
DEFAULTDB.DB().SetMaxIdleConns(100)
|
|
}
|
|
return DEFAULTDB
|
|
}
|