db.go 1.1 KB

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