Reputation: 568
I have table "BusinessHours" that contains days of the week of the store with opening Hours and Closing hours.
I want to update the values with one query! how to achieve this with sequelize ?
That's the table of the business hours and these are related to one store
Note: that in one query I want to update the whole row for each day.
Upvotes: 0
Views: 458
Reputation: 81
In Sequelize, assuming you have a model setup for this, you can update all of the applicable days of the week that have the same hours by using the following:
await BusinessHours.update(
{
openingTime: <date>,
closingTime: <date>,
},
{
where: {
dayOfTheWeek: ['mon', 'tues', ...],
}
}
)
If you would like to update any series of days that have different values, those would have to be separate queries.
Keep in mind, you may want to include the storeId
in your where
statement depending on your requirements.
https://sequelize.org/api/v6/class/src/model.js~model#static-method-update
Upvotes: 2