0

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.

enter image description here

3
  • 1
    If you want to update different rows with different values then you need to use a cycle because even SQL does not support that in general. Commented Feb 6, 2023 at 16:28
  • @Anatoly you mean make a for loop ? Commented Feb 6, 2023 at 17:37
  • 1
    Exactly, the for loop Commented Feb 6, 2023 at 17:53

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.