db.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "hongze/hongze_api/utils"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. func init() {
  9. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  10. orm.SetMaxIdleConns("default", 50)
  11. orm.SetMaxOpenConns("default", 100)
  12. db, _ := orm.GetDB("default")
  13. db.SetConnMaxLifetime(10 * time.Minute)
  14. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  15. orm.SetMaxIdleConns("rddp", 50)
  16. orm.SetMaxOpenConns("rddp", 100)
  17. report_db, _ := orm.GetDB("rddp")
  18. report_db.SetConnMaxLifetime(10 * time.Minute)
  19. //_ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
  20. //orm.SetMaxIdleConns("edb", 50)
  21. //orm.SetMaxOpenConns("edb", 100)
  22. //edb_db, _ := orm.GetDB("edb")
  23. //edb_db.SetConnMaxLifetime(10 * time.Minute)
  24. _ = orm.RegisterDataBase("rddp_trial", "mysql", utils.MYSQL_URL_RDDP_TRIAL)
  25. orm.SetMaxIdleConns("rddp_trial", 50)
  26. orm.SetMaxOpenConns("rddp_trial", 100)
  27. rddpTrial, _ := orm.GetDB("rddp_trial")
  28. rddpTrial.SetConnMaxLifetime(10 * time.Minute)
  29. orm.Debug = true
  30. orm.DebugLog = orm.NewLog(utils.Binlog)
  31. //注册对象
  32. orm.RegisterModel(
  33. new(ReportAudioRecord),
  34. new(ReportViewLog),
  35. new(ReportViewRecord),
  36. new(WxUser),
  37. new(Session),
  38. new(MsgCode),
  39. new(GraphicVerifyCode),
  40. new(AnnualReport),
  41. new(WxUserLog),
  42. new(UserAccessRecord),
  43. new(WxUserCode),
  44. new(UserRecord),
  45. new(YbApplyRecord),
  46. new(EnglishReportEmailPV),
  47. )
  48. }