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

5 years ago
5 years ago
  1. package qmsql
  2. import (
  3. "github.com/jinzhu/gorm"
  4. _ "github.com/jinzhu/gorm/dialects/mysql"
  5. "log"
  6. "main/config"
  7. )
  8. var DEFAULTDB *gorm.DB
  9. //初始化数据库并产生数据库全局变量
  10. func InitMysql(admin config.Admin) *gorm.DB {
  11. if db, err := gorm.Open("mysql", admin.Username+":"+admin.Password+"@("+admin.Path+")/"+admin.Dbname+"?"+admin.Config); err != nil {
  12. log.Printf("DEFAULTDB数据库启动异常%S", err)
  13. } else {
  14. DEFAULTDB = db
  15. DEFAULTDB.DB().SetMaxIdleConns(10)
  16. DEFAULTDB.DB().SetMaxIdleConns(100)
  17. }
  18. return DEFAULTDB
  19. }