common.go 398 B

123456789101112131415161718192021
  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. for _, val := range models {
  12. //fmt.Println(val.Model)
  13. err := Db.Set("gorm:table_options", "comment '"+val.Comment+"'").AutoMigrate(val.Model)
  14. if err != nil {
  15. panic(fmt.Sprintf("AutoMigrate err : %v", err))
  16. }
  17. }
  18. }