Update Data in MySQL Database Using Sequelize and Nodejs

Posted on by By admin, in Databases | 0

Sequelize is an ORM tool which is used to save data from node application to the databases like MySQL, Postgres and many others and a Model is basically a table in the database.

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

In this blog we will go through the process of updating the data in MySQL models. Setup of the application and models please refer this blog ‘Creating Models Using Sequelize’.

Let us consider a model named ‘COLORS’ that is already created and data is available with id as 5 and value as ‘RED’ and we should update the value for id 5 to ‘BLUE’ and the code is as follows

db.colors.update(
  { value: 'BLUE'},	
  { where: { id: 5 } },	 
raw : true			
)
.then((changed_data, rowsupdated) => {
	console.log(changed_data, rowsupdated)
})
.catch((error) => {
	console.log('error', error)
})

In the above code ‘value: ‘BLUE’ is the value that is to be updated and it should be provided with its attribute, ‘where : {id : 5}’ is the condition in which the data is to be updated. ‘raw:true’ this specifies Sequelize to return only data object instead of complete database object. In then() we can access the data with changed_variable and rows_updated will give the count of the rows those are updated.

Make data easy with Helical Insight.
Helical Insight is the world’s best open source business intelligence tool.

Saving Image to MYSQL and displaying it using Nodejs and Sequelizejs

For Further queries please get back to us at support@helicaltech.com

Thanks
Gagan Manda
BI Developer
Helical IT Solutions Pvt Ltd

logo

Best Open Source Business Intelligence Software Helical Insight Here

logo

A Business Intelligence Framework


logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments