db.go 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "hongze/hongze_cygxzs/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("hz_cygx", "mysql", utils.MYSQL_URL_CYGX)
  15. orm.SetMaxIdleConns("hz_cygx", 50)
  16. orm.SetMaxOpenConns("hz_cygx", 100)
  17. cygx_db, _ := orm.GetDB("hz_cygx")
  18. cygx_db.SetConnMaxLifetime(10 * time.Minute)
  19. //注册对象
  20. orm.RegisterModel(
  21. new(WxUser),
  22. new(WxUserLog),
  23. new(WxUserCode),
  24. new(UserRecord),
  25. new(CygxUserRecord),
  26. new(CygxXzsSession),
  27. new(CygxXzsChooseSend),
  28. new(CygxIndustryFllow),
  29. new(CygxXzsChooseCategory),
  30. new(CygxXzsChooseCategoryZhouqi), //周期的关注系列
  31. )
  32. // 记录ORM查询日志
  33. orm.Debug = true
  34. orm.DebugLog = orm.NewLog(utils.BinLog)
  35. }