db_init.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/article"
  7. "hongze/hongze_open_api/models/tables/company"
  8. "hongze/hongze_open_api/models/tables/open_api_user"
  9. "hongze/hongze_open_api/models/tables/wx_user"
  10. "hongze/hongze_open_api/utils"
  11. "time"
  12. )
  13. func init() {
  14. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  15. orm.SetMaxIdleConns("default", 50)
  16. orm.SetMaxOpenConns("default", 100)
  17. db, _ := orm.GetDB("default")
  18. db.SetConnMaxLifetime(10 * time.Minute)
  19. //rddp数据库
  20. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  21. orm.SetMaxIdleConns("rddp", 50)
  22. orm.SetMaxOpenConns("rddp", 100)
  23. report_db, _ := orm.GetDB("rddp")
  24. report_db.SetConnMaxLifetime(10 * time.Minute)
  25. //注册对象
  26. orm.RegisterModel(
  27. new(open_api_user.OpenApiUser), //开放API用户表
  28. new(company.Company), //company客户表
  29. new(wx_user.WxUser), //微信用户表
  30. new(admin.Admin), //系统用户表
  31. new(article.CygxArticleCeluePush), //策略平台推送过来更新的文章
  32. )
  33. }
  34. func InitDb() {}