db.go 769 B

12345678910111213141516171819202122232425262728293031
  1. package models
  2. import (
  3. "eta/eta_data_init/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. _ "github.com/go-sql-driver/mysql"
  6. "time"
  7. )
  8. func init() {
  9. if utils.MYSQL_URL_ETA != "" {
  10. _ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
  11. orm.SetMaxIdleConns("eta", 50)
  12. orm.SetMaxOpenConns("eta", 100)
  13. etaDb, _ := orm.GetDB("eta")
  14. etaDb.SetConnMaxLifetime(10 * time.Minute)
  15. orm.Debug = true
  16. orm.DebugLog = orm.NewLog(utils.Binlog)
  17. }
  18. if utils.MYSQL_URL_DATA != "" {
  19. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  20. orm.SetMaxIdleConns("data", 50)
  21. orm.SetMaxOpenConns("data", 100)
  22. etaDb, _ := orm.GetDB("data")
  23. etaDb.SetConnMaxLifetime(10 * time.Minute)
  24. orm.Debug = true
  25. orm.DebugLog = orm.NewLog(utils.Binlog)
  26. }
  27. }