common.go 488 B

123456789101112131415161718192021222324
  1. package dao
  2. import (
  3. "fmt"
  4. "gorm.io/gorm"
  5. "iot_manager_service/util/common"
  6. )
  7. var Db *gorm.DB
  8. func InitDB(db *gorm.DB) {
  9. Db = db
  10. models := []common.TableModelAuto{
  11. {&LightRecord{}, "亮灯记录表"},
  12. {&AkeyAlarmRecord{}, "一键求助记录表"},
  13. }
  14. for _, val := range models {
  15. //fmt.Println(val.Model)
  16. err := Db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
  17. if err != nil {
  18. panic(fmt.Sprintf("AutoMigrate err : %v", err))
  19. }
  20. }
  21. }