db.go 1023 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. )
  31. }
  32. // initEdbData 指标服务 数据表
  33. func initEdbData() {
  34. orm.RegisterModel(
  35. new(EdbInfoCalculateMapping),
  36. new(EdbInfo),
  37. )
  38. }
  39. // 初始化用户服务
  40. func initUser() {
  41. orm.RegisterModel(
  42. new(system.SysSession),
  43. new(system.SysUserLoginRecord),
  44. new(system.Admin),
  45. new(system.AdminOperateRecord),
  46. )
  47. }