统一初始beego mvc 的方法
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.

28 lines
616 B

  1. package db
  2. import (
  3. "github.com/astaxie/beego"
  4. "github.com/astaxie/beego/orm"
  5. "golib.gaore.com/GaoreGo/grlogs"
  6. )
  7. func LoadOrm(dsns map[string]dsnConfig) (err error) {
  8. for alias, dsn := range dsns {
  9. grlogs.Debug("init_db 正在加载数据 ", dsn)
  10. err = orm.RegisterDataBase(alias, dsn.Driver, dsn.Dsn, 10, 10)
  11. orm.SetMaxIdleConns(alias, 1000)
  12. orm.SetMaxOpenConns(alias, 1000)
  13. d, _ := orm.GetDB(alias)
  14. d.SetConnMaxLifetime(3600)
  15. }
  16. grlogs.Debug("init_db 加载数据库完成")
  17. // 测试环境下输出sql
  18. runmode := beego.BConfig.RunMode
  19. if runmode == "dev" {
  20. orm.Debug = true
  21. }
  22. return
  23. }