...
|
...
|
@@ -73,6 +73,28 @@ func Delete(db *gorm.DB, tableName string, fields []*domain.FieldValue) error { |
|
|
return tx.Error
|
|
|
}
|
|
|
|
|
|
func BatchDelete(db *gorm.DB, tableName string, fields []*domain.FieldValues) error {
|
|
|
var pk *domain.FieldValue
|
|
|
var values = make([]string, 0)
|
|
|
for _, row := range fields {
|
|
|
for _, f := range row.FieldValues {
|
|
|
if f.Field.Flag == domain.PKField && f.Value != "" {
|
|
|
pk = f
|
|
|
values = append(values, f.Value)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if len(values) == 0 {
|
|
|
return fmt.Errorf("删除行为空")
|
|
|
}
|
|
|
sql := db.ToSQL(func(tx *gorm.DB) *gorm.DB {
|
|
|
c := Condition{}
|
|
|
return tx.Table(tableName).Where(fmt.Sprintf("%s in %s", pk.Field.SQLName, c.InArgs(values))).Delete("")
|
|
|
})
|
|
|
tx := db.Exec(sql)
|
|
|
return tx.Error
|
|
|
}
|
|
|
|
|
|
//DROP VIEW IF EXISTS
|
|
|
|
|
|
func DropView(db *gorm.DB, tableName string) error {
|
...
|
...
|
|