db.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package models
  2. import (
  3. "eta/eta_report/utils"
  4. _ "github.com/go-sql-driver/mysql"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. func init() {
  9. // eta_report
  10. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  11. orm.SetMaxIdleConns("default", 50)
  12. orm.SetMaxOpenConns("default", 100)
  13. db, _ := orm.GetDB("default")
  14. db.SetConnMaxLifetime(10 * time.Minute)
  15. // eta_master
  16. _ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
  17. orm.SetMaxIdleConns("eta", 50)
  18. orm.SetMaxOpenConns("eta", 100)
  19. etaDb, _ := orm.GetDB("eta")
  20. etaDb.SetConnMaxLifetime(10 * time.Minute)
  21. // crm_master
  22. if utils.MYSQL_WEEKLY_URL != `` && utils.BusinessCode == utils.BusinessCodeRelease {
  23. _ = orm.RegisterDataBase("weekly", "mysql", utils.MYSQL_WEEKLY_URL)
  24. orm.SetMaxIdleConns("weekly", 50)
  25. orm.SetMaxOpenConns("weekly", 100)
  26. weeklyDb, _ := orm.GetDB("weekly")
  27. weeklyDb.SetConnMaxLifetime(10 * time.Minute)
  28. }
  29. orm.Debug = true
  30. orm.DebugLog = orm.NewLog(utils.Binlog)
  31. //注册对象
  32. orm.RegisterModel(
  33. new(Report),
  34. new(SmartReport),
  35. )
  36. }