db.go 903 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package models
  2. import (
  3. "eta/eta_pub/utils"
  4. _ "github.com/go-sql-driver/mysql"
  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("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("cygx", "mysql", utils.MYSQL_URL_CYGX)
  20. orm.SetMaxIdleConns("cygx", 50)
  21. orm.SetMaxOpenConns("cygx", 100)
  22. cygx_db, _ := orm.GetDB("cygx")
  23. cygx_db.SetConnMaxLifetime(10 * time.Minute)
  24. //注册对象
  25. orm.RegisterModel(
  26. new(UserTemplateRecord),
  27. new(ReportChapter),
  28. new(TemplateLibrary),
  29. )
  30. }