作者 yangfu

chore: batch delete table rows

... ... @@ -54,11 +54,14 @@ func (ptr *TableEditDataService) RowEdit(ctx *domain.Context, request domain.Edi
}); err != nil {
return nil, err
}
for _, l := range request.RemoveList {
if e := ptr.remove(ctx, table, l, request.Where); e != nil {
log.Logger.Error(e.Error())
}
if err = starrocks.BatchDelete(starrocks.DB, table.SQLName, request.RemoveList); err != nil {
return nil, err
}
//for _, l := range request.RemoveList {
// if e := ptr.remove(ctx, table, l, request.Where); e != nil {
// log.Logger.Error(e.Error())
// }
//}
}
for _, l := range request.UpdateList {
if e := ptr.update(ctx, table, l, request.Where); e != nil {
... ...
... ... @@ -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 {
... ...