gorm.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package initialize
  2. import (
  3. "go.uber.org/zap"
  4. "gorm.io/gorm"
  5. "os"
  6. "server/dao"
  7. "server/global"
  8. "server/model/example"
  9. )
  10. func Gorm() *gorm.DB {
  11. switch global.GVA_CONFIG.System.DbType {
  12. case "mysql":
  13. return GormMysql()
  14. case "pgsql":
  15. return GormPgSql()
  16. case "oracle":
  17. return GormOracle()
  18. case "mssql":
  19. return GormMssql()
  20. case "sqlite":
  21. return GormSqlite()
  22. default:
  23. return GormMysql()
  24. }
  25. }
  26. func RegisterTables() {
  27. db := global.GVA_DB
  28. err := db.AutoMigrate(
  29. dao.SysApi{},
  30. dao.SysUser{},
  31. dao.SysBaseMenu{},
  32. dao.JwtBlacklist{},
  33. dao.SysAuthority{},
  34. dao.SysDictionary{},
  35. dao.SysOperationRecord{},
  36. dao.SysDictionaryDetail{},
  37. dao.SysBaseMenuParameter{},
  38. dao.SysBaseMenuBtn{},
  39. dao.SysAuthorityBtn{},
  40. example.ExaFile{},
  41. example.ExaFileChunk{},
  42. dao.ExaFileUploadAndDownload{},
  43. dao.Region{},
  44. dao.Tunnel{},
  45. dao.TunnelTime{},
  46. dao.Device{},
  47. dao.DeviceGenre{},
  48. dao.DeviceRelay{},
  49. dao.EnvData{},
  50. dao.OpticalData{},
  51. )
  52. if err != nil {
  53. global.GVA_LOG.Error("register table failed", zap.Error(err))
  54. os.Exit(0)
  55. }
  56. global.GVA_LOG.Info("register table success")
  57. }