db.go 927 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.Debug = true
  16. orm.DebugLog = orm.NewLog(utils.Binlog)
  17. initChart()
  18. initEdbData()
  19. initSystem()
  20. }
  21. // initChart 图表 数据表
  22. func initChart() {
  23. orm.RegisterModel(
  24. new(ChartClassify),
  25. new(ChartInfo),
  26. new(ChartEdbMapping),
  27. new(ChartTheme),
  28. new(ChartThemeType),
  29. new(ChartSeries),
  30. new(ChartSeriesEdbMapping),
  31. )
  32. }
  33. // initEdbData 指标服务 数据表
  34. func initEdbData() {
  35. orm.RegisterModel(
  36. new(EdbInfoCalculateMapping),
  37. new(EdbInfo),
  38. )
  39. }
  40. func initSystem() {
  41. orm.RegisterModel(new(system.Admin))
  42. }