Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is multiple delete available in sequelize?

I have a multiple contentIds.

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.

like image 231
Anuj Avatar asked May 29 '14 08:05

Anuj


People also ask

How do I delete multiple data in Sequelize?

To delete rows of data from your SQL table using Sequelize, you need to use the provided destroy() method. The destroy() method can be called from any Model or instance of your Model to delete rows from your table.

How do I make multiple rows Sequelize?

Adding multiple rows at once using Sequelize bulkCreate() method. When you need to insert multiple rows to your SQL database table, you can use the Sequelize bulkCreate() method. The bulkCreate() method allows you to insert multiple records to your database table with a single function call.

Do companies use Sequelize?

Who uses Sequelize? 87 companies reportedly use Sequelize in their tech stacks, including Barogo, kevin., and Goopy.


2 Answers

Example:

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

For more details check the API docs.

like image 156
Sergey Karasev Avatar answered Sep 29 '22 19:09

Sergey Karasev


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;

like image 40
Mardari Avatar answered Sep 29 '22 19:09

Mardari