db.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package models
  2. import (
  3. _ "github.com/go-sql-driver/mysql"
  4. "hongze/hongze_chart_lib/models/data_manage"
  5. "hongze/hongze_chart_lib/models/data_manage/future_good"
  6. "hongze/hongze_chart_lib/utils"
  7. "time"
  8. "github.com/beego/beego/v2/client/orm"
  9. )
  10. func init() {
  11. _ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
  12. orm.SetMaxIdleConns("default", 50)
  13. orm.SetMaxOpenConns("default", 100)
  14. db, _ := orm.GetDB("default")
  15. db.SetConnMaxLifetime(10 * time.Minute)
  16. _ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
  17. orm.SetMaxIdleConns("data", 50)
  18. orm.SetMaxOpenConns("data", 100)
  19. data_db, _ := orm.GetDB("data")
  20. data_db.SetConnMaxLifetime(10 * time.Minute)
  21. _ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
  22. orm.SetMaxIdleConns("edb", 50)
  23. orm.SetMaxOpenConns("edb", 100)
  24. edb_db, _ := orm.GetDB("edb")
  25. edb_db.SetConnMaxLifetime(10 * time.Minute)
  26. orm.Debug = true
  27. orm.DebugLog = orm.NewLog(utils.Binlog)
  28. //注册对象
  29. orm.RegisterModel(
  30. new(data_manage.EdbInfo),
  31. new(ShareChartRefreshLog), //分享图表刷新日志表
  32. new(ExcelInfo), //excel表格
  33. new(data_manage.PredictEdbConf), //预测指标配置
  34. new(data_manage.PredictEdbRuleData), //预测指标配置生成的数据
  35. new(data_manage.PredictEdbConfCalculateMapping), //预测指标关系表
  36. )
  37. // 期货数据库
  38. initFutureGood()
  39. }
  40. // initFutureGood 注册期货数据 数据表
  41. func initFutureGood() {
  42. //注册对象
  43. orm.RegisterModel(
  44. new(future_good.FutureGoodEdbInfo), //期货指标表
  45. new(future_good.FutureGoodEdbData), //期货指标数据表
  46. )
  47. }