db.go 981 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package models
  2. import (
  3. "eta/eta_mini_bridge/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("rddp", "mysql", utils.MYSQL_URL_RDDP)
  10. orm.SetMaxIdleConns("rddp", 50)
  11. orm.SetMaxOpenConns("rddp", 100)
  12. report_db, _ := orm.GetDB("rddp")
  13. report_db.SetConnMaxLifetime(10 * time.Minute)
  14. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  15. orm.SetMaxIdleConns("data", 50)
  16. orm.SetMaxOpenConns("data", 100)
  17. data_db, _ := orm.GetDB("data")
  18. data_db.SetConnMaxLifetime(10 * time.Minute)
  19. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL_MASTER)
  20. orm.SetMaxIdleConns("default", 50)
  21. orm.SetMaxOpenConns("default", 100)
  22. master_db, _ := orm.GetDB("default")
  23. master_db.SetConnMaxLifetime(10 * time.Minute)
  24. orm.Debug = true
  25. orm.DebugLog = orm.NewLog(utils.BinLog)
  26. // register model
  27. orm.RegisterModel(
  28. new(User),
  29. new(UserRecord),
  30. new(UserTemplateRecord),
  31. )
  32. }