Hello Friends,

Welcome To Infinitbility!

To update data in the database, sequelize provide update() method it will update your data on the database based on your condition. using sequelize update method we are able to write SQL update query in a function and JSON parameters.

This article based on sequelize update query, here you will get update query examples to do on your project.

If you are looking for sequelize basics query example for crud check below article it’s based on sequelize create, select, delete, and update, and join examples

https://infinitbility.com/node.js-sequelize-query-examples

Let’s start today’s article Node sequelize update query example

Today we will learn how many types update query have in Node sequelize.

update query with condition

When you want to update some field based on some condition then you can use simply update query provide by sequelize example like below.

// Change everyone without a last name to "Doe"
await User.update({ lastName: "Doe" }, {
  where: {
    lastName: null
  }
});

update query with select

sequelize provide option update query after selection done, like first select some data using findOne() after update record using save() understand with example.

const user = User.findOne({
  attributes: ['first_name', 'last_name'],
  where: {
    id: 2
  }
});

user.first_name = "infinitbility";
user.save();

Thanks for reading…