Categories
JavaScript Answers

How to update record, and return result with Sequelize and JavaScript?

Spread the love

Sometimes, we want to update record, and return result with Sequelize and JavaScript.

In this article, we’ll look at how to update record, and return result with Sequelize and JavaScript.

How to update record, and return result with Sequelize and JavaScript?

To update record, and return result with Sequelize and JavaScript, we can use the db.connections.update method.

For instance, we write

const result = await db.connections.update(
  {
    user: data.username,
    chatroomID: data.chatroomID,
  },
  {
    where: { socketID: socket.id },
    returning: true,
    plain: true,
  }
);

to call db.connection.update to update the user and chatroomID values.

We set returning to true to return the updated entry as an object with the promise returned by update.

Conclusion

To update record, and return result with Sequelize and JavaScript, we can use the db.connections.update method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.