db.go 886 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. _ "github.com/go-sql-driver/mysql"
  5. "hongze/hongze_edb_lib/utils"
  6. "time"
  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. orm.Debug = true
  25. //注册对象
  26. orm.RegisterModel(
  27. new(EdbDataCalculateZjpj),
  28. new(EdbDataCalculateLjztbpj),
  29. )
  30. }