db.go 924 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "hongze/hongze_mfyx_gzh/utils"
  5. "time"
  6. "github.com/beego/beego/v2/client/orm"
  7. )
  8. func init() {
  9. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL_CYGX)
  10. orm.SetMaxIdleConns("default", 50)
  11. orm.SetMaxOpenConns("default", 100)
  12. cygx_db, _ := orm.GetDB("default")
  13. cygx_db.SetConnMaxLifetime(10 * time.Minute)
  14. _ = orm.RegisterDataBase("weekly_report", "mysql", utils.MYSQL_URL)
  15. orm.SetMaxIdleConns("weekly_report", 50)
  16. orm.SetMaxOpenConns("weekly_report", 100)
  17. db, _ := orm.GetDB("weekly_report")
  18. db.SetConnMaxLifetime(10 * time.Minute)
  19. //注册对象
  20. orm.RegisterModel(
  21. new(WxUser),
  22. new(WxUserLog),
  23. new(WxUserCode),
  24. new(UserRecord),
  25. new(CygxMfyxGzhUserRecord),
  26. new(CygxMfyxGzhSession),
  27. new(CygxIndustryFllow),
  28. new(CygxThreeApiLog),
  29. )
  30. // 记录ORM查询日志
  31. orm.Debug = true
  32. orm.DebugLog = orm.NewLog(utils.Binlog)
  33. }