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
566 B

5 years ago
5 years ago
  1. package qmsql
  2. import (
  3. "gin-vue-admin/config"
  4. "github.com/jinzhu/gorm"
  5. _ "github.com/jinzhu/gorm/dialects/mysql"
  6. "log"
  7. )
  8. var DEFAULTDB *gorm.DB
  9. //初始化数据库并产生数据库全局变量
  10. func InitMysql(admin config.MysqlAdmin) *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().SetMaxOpenConns(100)
  17. }
  18. return DEFAULTDB
  19. }