|
@ -1,10 +1,12 @@ |
|
|
package qmsql |
|
|
package qmsql |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"gin-vue-admin/config" |
|
|
|
|
|
|
|
|
"log" |
|
|
|
|
|
|
|
|
"github.com/jinzhu/gorm" |
|
|
"github.com/jinzhu/gorm" |
|
|
_ "github.com/jinzhu/gorm/dialects/mysql" |
|
|
_ "github.com/jinzhu/gorm/dialects/mysql" |
|
|
"log" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"gin-vue-admin/config" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var DEFAULTDB *gorm.DB |
|
|
var DEFAULTDB *gorm.DB |
|
@ -12,7 +14,8 @@ var DEFAULTDB *gorm.DB |
|
|
//初始化数据库并产生数据库全局变量
|
|
|
//初始化数据库并产生数据库全局变量
|
|
|
func InitMysql(admin config.MysqlAdmin) *gorm.DB { |
|
|
func InitMysql(admin config.MysqlAdmin) *gorm.DB { |
|
|
if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil { |
|
|
if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil { |
|
|
log.Printf("DEFAULTDB数据库启动异常%S", err) |
|
|
|
|
|
|
|
|
// 数据库初始化失败时,直接退出程序
|
|
|
|
|
|
log.Fatalf("DEFAULTDB数据库启动异常: %s", err) |
|
|
} else { |
|
|
} else { |
|
|
DEFAULTDB = db |
|
|
DEFAULTDB = db |
|
|
DEFAULTDB.DB().SetMaxIdleConns(10) |
|
|
DEFAULTDB.DB().SetMaxIdleConns(10) |
|
|