gorm.go 1.0 KB

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