common.go 422 B

12345678910111213141516171819202122
  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. err := Db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
  15. if err != nil {
  16. panic(fmt.Sprintf("AutoMigrate err : %v", err))
  17. }
  18. }
  19. }