db_init.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "github.com/rdlucklib/rdluck_tools/orm"
  5. "hongze/hongze_open_api/models/tables/admin"
  6. "hongze/hongze_open_api/models/tables/company"
  7. "hongze/hongze_open_api/models/tables/open_api_user"
  8. "hongze/hongze_open_api/models/tables/wx_user"
  9. "hongze/hongze_open_api/utils"
  10. "time"
  11. )
  12. func init() {
  13. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  14. orm.SetMaxIdleConns("default", 50)
  15. orm.SetMaxOpenConns("default", 100)
  16. db, _ := orm.GetDB("default")
  17. db.SetConnMaxLifetime(10 * time.Minute)
  18. //rddp数据库
  19. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  20. orm.SetMaxIdleConns("rddp", 50)
  21. orm.SetMaxOpenConns("rddp", 100)
  22. report_db, _ := orm.GetDB("rddp")
  23. report_db.SetConnMaxLifetime(10 * time.Minute)
  24. //注册对象
  25. orm.RegisterModel(
  26. new(open_api_user.OpenApiUser), //开放API用户表
  27. new(company.Company), //company客户表
  28. new(wx_user.WxUser), //微信用户表
  29. new(admin.Admin), //系统用户表
  30. )
  31. }
  32. func InitDb() {}