批量删除
Example
type User struct {
ID int `orm:"id"`
Name string `orm:"name"`
}
func DeleteUserAll(ids []int) {
o := orm.NewOrm()
qs := o.QueryTable(new(User))
_, err := qs.Filter("id__in", ids).Delete()
if err != nil {
fmt.Printf("delete User by Ids fail: [%v]\n", err)
return
}
fmt.Printf("delete users by ids success\n")
}
流程
- 根据对应表, 构建QuerySeter对象
- 添加查询条件
- 在最后的结构集上调用Delete()函数