db.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package models
  2. import (
  3. "eta/eta_forum_task/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. _ "github.com/go-sql-driver/mysql"
  6. "time"
  7. )
  8. func init() {
  9. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  10. orm.SetMaxIdleConns("default", 50)
  11. orm.SetMaxOpenConns("default", 100)
  12. db, _ := orm.GetDB("default")
  13. db.SetConnMaxLifetime(10 * time.Minute)
  14. _ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
  15. orm.SetMaxIdleConns("rddp", 50)
  16. orm.SetMaxOpenConns("rddp", 100)
  17. report_db, _ := orm.GetDB("rddp")
  18. report_db.SetConnMaxLifetime(10 * time.Minute)
  19. _ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
  20. orm.SetMaxIdleConns("edb", 50)
  21. orm.SetMaxOpenConns("edb", 100)
  22. edb_db, _ := orm.GetDB("edb")
  23. edb_db.SetConnMaxLifetime(10 * time.Minute)
  24. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  25. orm.SetMaxIdleConns("data", 50)
  26. orm.SetMaxOpenConns("data", 100)
  27. data_db, _ := orm.GetDB("data")
  28. data_db.SetConnMaxLifetime(10 * time.Minute)
  29. _ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
  30. orm.SetMaxIdleConns("gl", 50)
  31. orm.SetMaxOpenConns("gl", 100)
  32. gl, _ := orm.GetDB("gl")
  33. gl.SetConnMaxLifetime(10 * time.Minute)
  34. orm.Debug = true
  35. orm.DebugLog = orm.NewLog(utils.Binlog)
  36. initChart()
  37. initEdbData()
  38. afterInitTable()
  39. }
  40. // initChart 图表 数据表
  41. func initChart() {
  42. orm.RegisterModel(
  43. new(ChartClassify),
  44. new(ChartInfo),
  45. new(ChartEdbMapping),
  46. new(ChartTheme),
  47. new(ChartThemeType),
  48. )
  49. }
  50. // initEdbData 指标服务 数据表
  51. func initEdbData() {
  52. orm.RegisterModel(
  53. new(EdbInfoCalculateMapping),
  54. new(EdbInfo),
  55. )
  56. }
  57. // afterInitTable
  58. // @Description: 初始化表结构的的后置操作
  59. // @author: Roc
  60. // @datetime 2024-07-01 13:31:09
  61. func afterInitTable() {
  62. InitEdbSourceVar()
  63. // 初始化是否启用mongo配置
  64. InitUseMongoConf()
  65. }