db.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package models
  2. import (
  3. "eta/eta_mini_api/utils"
  4. "time"
  5. "github.com/beego/beego/v2/client/orm"
  6. _ "github.com/go-sql-driver/mysql"
  7. )
  8. func init() {
  9. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL_MASTER)
  10. orm.SetMaxIdleConns("default", 50)
  11. orm.SetMaxOpenConns("default", 100)
  12. master_db, _ := orm.GetDB("default")
  13. master_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. _ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL)
  20. orm.SetMaxIdleConns("eta", 50)
  21. orm.SetMaxOpenConns("eta", 100)
  22. db, _ := orm.GetDB("eta")
  23. db.SetConnMaxLifetime(10 * time.Minute)
  24. orm.Debug = true
  25. orm.DebugLog = orm.NewLog(utils.BinLog)
  26. // register model
  27. orm.RegisterModel(
  28. new(MsgCode),
  29. new(MyChart),
  30. new(MyReport),
  31. new(User),
  32. new(WxToken),
  33. new(Banner),
  34. new(WxSession),
  35. new(UserRecord),
  36. new(UserTemplateRecord),
  37. new(UserReadRecord),
  38. new(UserReadPermission1),
  39. new(UserReadPermission2),
  40. )
  41. }