db.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "hongze/hongze_cygx/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("tactics", "mysql", utils.MYSQL_URL_TACTICS)
  20. orm.SetMaxIdleConns("tactics", 50)
  21. orm.SetMaxOpenConns("tactics", 100)
  22. tacticsDb, _ := orm.GetDB("tactics")
  23. tacticsDb.SetConnMaxLifetime(10 * time.Minute)
  24. orm.RegisterDataBase("comein_data", "mysql", utils.MYSQL_URL_COMEIN_DATA)
  25. orm.SetMaxIdleConns("comein_data", 50)
  26. orm.SetMaxOpenConns("comein_data", 100)
  27. comein_datadb, _ := orm.GetDB("comein_data")
  28. comein_datadb.SetConnMaxLifetime(10 * time.Minute)
  29. //
  30. //orm.RegisterDataBase("comein_data", "mysql", utils.MYSQL_URL_COMEIN_DATA)
  31. //orm.SetMaxIdleConns("comein_data", 50)
  32. //orm.SetMaxOpenConns("comein_data", 100)
  33. //
  34. //comein_dataDb, _ := orm.GetDB("comein_data")
  35. //comein_dataDb.SetConnMaxLifetime(10 * time.Minute)
  36. //注册对象
  37. orm.RegisterModel(
  38. new(WxUser),
  39. new(CygxSession),
  40. new(WxUserLog),
  41. new(WxUserCode),
  42. new(CygxArticleCollect),
  43. new(CygxArticleViewRecord),
  44. new(CygxAdvice),
  45. new(MsgCode),
  46. new(Resource),
  47. new(CygxApplyRecord),
  48. new(CygxInterviewApply),
  49. new(CygxArticle),
  50. new(CygxArticleHistoryRecord),
  51. new(CygxSearchKeyWord),
  52. new(UserRecord),
  53. new(CygxIndustryTop),
  54. new(CygxActivitySignup),
  55. new(CygxActivitySignupLog),
  56. new(CygxActivityUserSearchContent),
  57. new(CygxActivityMeetingReminder),
  58. new(CygxActivityMeetingReminderLog),
  59. new(CygxMySchedule),
  60. new(WxUserWhite),
  61. new(CygxActivityHelpAsk),
  62. new(CygxIndustryFllow),
  63. new(CygxArticleDepartmentFollow),
  64. new(CygxArticleAsk),
  65. new(CygxPageHistoryRecord),
  66. new(CygxReportHistoryRecord),
  67. new(CygxArticleAuthor),
  68. new(CygxUserRecord),
  69. new(CygxReportIndustrialSeaarchHistory),
  70. new(CygxArticleHistoryRecordNewpv),
  71. new(CygxActivitySearchHistory),
  72. new(CygxActivityAttendanceDetail),
  73. new(CygxActivityRestrictSignup),
  74. new(CygxActivityMeetDetailLog),
  75. new(CygxUserSearchKeyWord),
  76. new(CompanyReportPermission),
  77. new(Company),
  78. new(CompanyLog),
  79. new(CompanyOperationRecord),
  80. new(CompanyPermissionLog),
  81. new(CompanyProduct),
  82. new(CompanyProductLog),
  83. new(UserSellerRelation),
  84. new(CygxShanghaiCompanyLog),
  85. new(CygxShanghaiErrLog),
  86. new(CygxUserFreeeButton),
  87. new(UserInvitee),
  88. new(CygxActivitySpecialSignup),
  89. new(CygxUserFollowSpecial),
  90. new(CygxChart),
  91. new(CygxChartCollect),
  92. new(CygxChartTop),
  93. new(CygxCelueArticleHistoryRecord),
  94. new(CygxArticleHistoryRecordAll),
  95. new(CygxActivityAppointment),
  96. new(UserTemplateRecord),
  97. new(CygxUserInteractionNum),
  98. new(CygxChartCollectByCygx),
  99. )
  100. // 记录ORM查询日志
  101. orm.Debug = true
  102. orm.DebugLog = orm.NewLog(utils.BinLog)
  103. }