db.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "hongze/hongze_clpt/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. //注册对象
  20. orm.RegisterModel(
  21. new(WxUser),
  22. new(WxUserCode),
  23. new(UserRecord),
  24. new(CygxUserRecord),
  25. new(CygxClptSession),
  26. new(CygxIndustryFllow),
  27. new(MsgCode),
  28. new(CygxArticleCollect),
  29. new(CygxInterviewApply),
  30. new(CygxArticleAsk),
  31. new(CygxSearchKeyWord),
  32. new(CygxSearchKeyWordLog),
  33. new(Resource),
  34. new(CygxXzsChooseCategory),
  35. new(CygxReportIndustrialSeaarchHistory),
  36. new(CygxMicroRoadshowVideoHistory),
  37. )
  38. // 记录ORM查询日志
  39. orm.Debug = true
  40. orm.DebugLog = orm.NewLog(utils.BinLog)
  41. }