db.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package models
  2. import (
  3. "eta/eta_forum_hub/models/system"
  4. "eta/eta_forum_hub/utils"
  5. "github.com/beego/beego/v2/client/orm"
  6. _ "github.com/go-sql-driver/mysql"
  7. "time"
  8. )
  9. func init() {
  10. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  11. orm.SetMaxIdleConns("default", 50)
  12. orm.SetMaxOpenConns("default", 100)
  13. db, _ := orm.GetDB("default")
  14. db.SetConnMaxLifetime(10 * time.Minute)
  15. _ = orm.RegisterDataBase("weekly_trial", "mysql", utils.MYSQL_URL_WEEKLY_TRIAL)
  16. orm.SetMaxIdleConns("weekly_trial", 50)
  17. orm.SetMaxOpenConns("weekly_trial", 100)
  18. _ = orm.RegisterDataBase("edb_trial", "mysql", utils.MYSQL_URL_EDB_TRIAL)
  19. orm.SetMaxIdleConns("edb_trial", 50)
  20. orm.SetMaxOpenConns("edb_trial", 100)
  21. _ = orm.RegisterDataBase("hz_data_trial", "mysql", utils.MYSQL_URL_HZ_DATA_TRIAL)
  22. orm.SetMaxIdleConns("hz_data_trial", 50)
  23. orm.SetMaxOpenConns("hz_data_trial", 100)
  24. orm.Debug = true
  25. orm.DebugLog = orm.NewLog(utils.Binlog)
  26. initChart()
  27. initEdbData()
  28. initSystem()
  29. initEtaTrial()
  30. }
  31. // initChart 图表 数据表
  32. func initChart() {
  33. orm.RegisterModel(
  34. new(ChartClassify),
  35. new(ChartInfo),
  36. new(ChartEdbMapping),
  37. new(ChartTheme),
  38. new(ChartThemeType),
  39. new(ChartSeries),
  40. new(ChartSeriesEdbMapping),
  41. new(ChartDescription),
  42. )
  43. }
  44. // initEdbData 指标服务 数据表
  45. func initEdbData() {
  46. orm.RegisterModel(
  47. new(EdbInfoCalculateMapping),
  48. new(EdbInfo),
  49. )
  50. }
  51. func initSystem() {
  52. orm.RegisterModel(
  53. new(system.Admin),
  54. new(system.SysRole),
  55. new(system.SysDepartment),
  56. new(system.SysGroup),
  57. )
  58. }
  59. // initEtaTrial 试用相关
  60. func initEtaTrial() {
  61. orm.RegisterModel(
  62. new(EtaTrial),
  63. new(EtaTrialActiveRecord),
  64. new(EtaTrialLoginDurationRecord),
  65. )
  66. }