db.go 704 B

12345678910111213141516171819202122232425262728293031
  1. package models
  2. import (
  3. "eta/eta_data_push/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. _ "github.com/go-sql-driver/mysql"
  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. // 用户主库
  15. _ = orm.RegisterDataBase("weekly", "mysql", utils.MYSQL_WEEKLY_URL)
  16. orm.SetMaxIdleConns("weekly", 50)
  17. orm.SetMaxOpenConns("weekly", 100)
  18. weeklyDb, _ := orm.GetDB("weekly")
  19. weeklyDb.SetConnMaxLifetime(10 * time.Minute)
  20. orm.Debug = true
  21. orm.DebugLog = orm.NewLog(utils.Binlog)
  22. //注册对象
  23. orm.RegisterModel()
  24. }