How can i combine two update requests into one?

Vladislav

I now have a code that works.

await Users.update({ selected: false }, { where: { userId: req.body.userId } });
await Users.update(
  {
    selected: req.body.selected,
    descr: req.body.note
  },
  {
    where:
    {
      entId: req.body.id,
      userId: req.body.userId
    }
  }
);

But what if it is possible to combine these two queries into one? I need the 'selected' and 'note' field that I pass to change conditionally in the table. And all other 'selected' fields inherent to the user in the table became false. Unfortunately, I did not find anything like that in the documentation. Thank you in advance for your help!

Anatoly

Unfortunately there is no such method like bulkUpdate in Sequelize so you need to call update twice and better to use a transaction to make these two queries as a one atomic operation.

await Sequelize.transaction(async transaction => {
  await Users.update({ selected: false }, { where: { userId: req.body.userId }, transaction });
  await Users.update(
    {
      selected: req.body.selected,
      descr: req.body.note
    },
    {
      where:
      {
        entId: req.body.id,
        userId: req.body.userId
      },
      transaction
    }
  );
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I combine two QStrings into one?

How can I combine these two queries into one?

How can I combine two userscripts into one?

How can I combine a comparison and an update in one atomic operation?

How can I combine the above two steps in one using loop

how can I combine two search code into one

Kivy: How can I combine the two screens into one?

How can I combine the two spiders into just one?

How can I combine two commits into one commit?

How can I combine two animated GIF images into one?

How can I combine two rows of a dataframe into one?

How can i combine two similar php codes into one?

How can I combine two lists into one long list?

How can I combine those two loops into one?

How can i combine these two Django annotated queries into one?

How can i combine these two into one list comprehension?

How can I combine two Django views into one?

Can I combine these two SQL queries into one?

Can I combine two "keybinds" into one in Openbox?

Can I combine two for statements into one?

CompletableFuture: how to combine two asynchronous requests into one response

How can I update two different tables in one query?

How can i update two table in one query in posgresql

How can i update one row usign two keys in laravel?

How do I combine two columns into one?

How I combine two wifi networks into one?

How can I combine two select statements into one table with two seperate columns?

How can I combine two views and two forms into one single template?

I need to join the two requests in one, how can I do it in angular/rxjs?