db.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. )
  42. }
  43. // initEdbData 指标服务 数据表
  44. func initEdbData() {
  45. orm.RegisterModel(
  46. new(EdbInfoCalculateMapping),
  47. new(EdbInfo),
  48. )
  49. }
  50. func initSystem() {
  51. orm.RegisterModel(
  52. new(system.Admin),
  53. new(system.SysRole),
  54. new(system.SysDepartment),
  55. new(system.SysGroup),
  56. )
  57. }
  58. // initEtaTrial 试用相关
  59. func initEtaTrial() {
  60. orm.RegisterModel(
  61. new(EtaTrial),
  62. new(EtaTrialActiveRecord),
  63. new(EtaTrialLoginDurationRecord),
  64. )
  65. }