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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *