db.go 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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("default", "mysql", utils.MYSQL_URL_ETA)
  11. orm.SetMaxIdleConns("default", 50)
  12. orm.SetMaxOpenConns("default", 100)
  13. orm.Debug = true
  14. orm.DebugLog = orm.NewLog(utils.Binlog)
  15. _ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
  16. orm.SetMaxIdleConns("eta", 50)
  17. orm.SetMaxOpenConns("eta", 100)
  18. etaDb, _ := orm.GetDB("eta")
  19. etaDb.SetConnMaxLifetime(10 * time.Minute)
  20. orm.RegisterModel(
  21. new(Admin),
  22. )
  23. orm.Debug = true
  24. orm.DebugLog = orm.NewLog(utils.Binlog)
  25. }
  26. if utils.MYSQL_URL_DATA != "" {
  27. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  28. orm.SetMaxIdleConns("data", 50)
  29. orm.SetMaxOpenConns("data", 100)
  30. etaDb, _ := orm.GetDB("data")
  31. etaDb.SetConnMaxLifetime(10 * time.Minute)
  32. orm.Debug = true
  33. orm.DebugLog = orm.NewLog(utils.Binlog)
  34. }
  35. }