node.js sequelize 中是否可以进行多次删除?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23929098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:25:31  来源:igfitidea点击:

Is multiple delete available in sequelize?

node.jssequelize.js

提问by Anuj

I have a multiple contentIds.

我有多个 contentId。

Mode.findAll({
    where: {
     id: contentIds
   }
  })

After finding all how can I Delete multiple rows from a table.

在找到所有如何从表中删除多行之后。

Or tell me other options to delete multiple records with a single query.

或者告诉我使用单个查询删除多个记录的其他选项。

回答by Sergey Karasev

Issuewith your question

问题与你的问题

Documentation

文档

Example:

例子:

Model.destroy({ where: { id: [1,2,3,4] }})

回答by Mardari

If you want to delete ALL models of a specific type, you can use:

如果要删除特定类型的所有模型,可以使用:

Model.destroy({where: {}}).then(function () {});

This will delete all records of type 'Model' from database. Tested with mysql;

这将从数据库中删除所有类型为“模型”的记录。用mysql测试;

回答by Juan Navarrete

To destroy all entries in a model:

要销毁模型中的所有条目:

Model.destroy({
    where: {}
}).then(function(){
    console.log('destroy all data');
    res.redirect('/');
})