db.go 694 B

123456789101112131415161718192021222324252627282930313233343536
  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. //注册对象
  15. orm.RegisterModel(
  16. new(WxUser),
  17. new(WxUserLog),
  18. new(WxUserCode),
  19. new(UserRecord),
  20. new(CygxUserRecord),
  21. new(CygxXzsSession),
  22. new(CygxXzsChooseSend),
  23. new(CygxIndustryFllow),
  24. new(CygxXzsChooseCategory),
  25. )
  26. // 记录ORM查询日志
  27. orm.Debug = true
  28. orm.DebugLog = orm.NewLog(utils.BinLog)
  29. }