db.go 919 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. )
  31. // 记录ORM查询日志
  32. orm.Debug = true
  33. orm.DebugLog = orm.NewLog(utils.Binlog)
  34. }