I'm using a raw query with sequelize to update multiple rows with one query in my postgres DB. For example:
update customers_table as c set
name = c2.name
from (values
(66, 'Joe'),
(70, 'Ann')
) as c2(id, name)
where c2.id = c.id;
In this example, two rows with the ids 66 and 70 will have their names updated.
But how do I pass in data to be updated as an array in nodejs via sequelizejs raw query? For example (this doesn't work, but I'm trying to get at what it is I'm trying to do):
const arrayOfData = [[66, 'Joe'], [70, 'Ann']];
const query =
`update customers_table as c set
name = c2.name
from (values
${arrayOfData}
) as c2(id, name)
where c2.id = c.id;`;
const update = sequelize.query(query).spread((results, metadata) => {
return results;
});
arrayOfDataformat would be something like this:const arrayOfData = [[66, 'Joe'], [70, 'Ann']];