Question

I've read the documentation of sequelize quite thoroughly and I can't seem to find any way to perform operations on multiple rows simultaneously. Something like

UPDATE mytable SET expired=1;

The only way I can see of doing this through sequelize would be to run mytable.all() and loop through each resulting row, setting expired to 1 and saving it. This would take the same amount of queries as there are rows in the table (could be thousands) instead of the one simple query.

Does sequelize perhaps have some undocumented method of doing this? Or perhaps just well hidden in the documentation? Is it possible to run custom SQL queries through some undocumented private field of sequelize?

Any info on the subject appreciated

Was it helpful?

Solution

it is currently not possible to perform an update on multiple rows at once. Nevertheless you can use the query-method of your sequelize instance. I just checked out if it is possible and, yeah, it is. Like this:

sequelize.query('UPDATE mytable SET expired=1')

Have phun!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top