common.go 449 B

1234567891011121314151617181920212223
  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. {&AkeyAlarmRecord{}, "一键求助记录表"},
  12. }
  13. for _, val := range models {
  14. //fmt.Println(val.Model)
  15. err := Db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
  16. if err != nil {
  17. panic(fmt.Sprintf("AutoMigrate err : %v", err))
  18. }
  19. }
  20. }