db.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package models
  2. import (
  3. "eta/eta_forum_admin/models/system"
  4. "eta/eta_forum_admin/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. initUser()
  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(ChartInfoLog),
  30. new(SearchKeyword),
  31. )
  32. }
  33. // initEdbData 指标服务 数据表
  34. func initEdbData() {
  35. orm.RegisterModel(
  36. new(EdbInfoCalculateMapping),
  37. new(EdbInfo),
  38. )
  39. }
  40. // 初始化用户服务
  41. func initUser() {
  42. orm.RegisterModel(
  43. new(system.SysSession),
  44. new(system.SysUserLoginRecord),
  45. new(system.Admin),
  46. new(system.AdminOperateRecord),
  47. )
  48. }