db.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // ETA默认库
  30. _ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
  31. orm.SetMaxIdleConns("eta", 50)
  32. orm.SetMaxOpenConns("eta", 100)
  33. etaDb, _ := orm.GetDB("eta")
  34. etaDb.SetConnMaxLifetime(10 * time.Minute)
  35. orm.Debug = true
  36. orm.DebugLog = orm.NewLog(utils.Binlog)
  37. //注册对象
  38. orm.RegisterModel(
  39. new(ReportAudioRecord),
  40. new(ReportViewLog),
  41. new(ReportViewRecord),
  42. new(WxUser),
  43. new(Session),
  44. new(MsgCode),
  45. new(GraphicVerifyCode),
  46. new(AnnualReport),
  47. new(WxUserLog),
  48. new(UserAccessRecord),
  49. new(WxUserCode),
  50. new(UserRecord),
  51. new(YbApplyRecord),
  52. new(EnglishReportEmailPV),
  53. )
  54. }