db.go 808 B

123456789101112131415161718192021222324252627282930313233343536
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "hongze/hongze_edb_lib/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. _ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
  15. orm.SetMaxIdleConns("edb", 50)
  16. orm.SetMaxOpenConns("edb", 100)
  17. edb_db, _ := orm.GetDB("edb")
  18. edb_db.SetConnMaxLifetime(10 * time.Minute)
  19. _ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
  20. orm.SetMaxIdleConns("gl", 50)
  21. orm.SetMaxOpenConns("gl", 100)
  22. gl, _ := orm.GetDB("gl")
  23. gl.SetConnMaxLifetime(10 * time.Minute)
  24. //注册对象
  25. orm.RegisterModel(
  26. )
  27. }