1const Tokens = db.define('tokens', {
2 token: {
3 type: sequelize.STRING
4 }
5});
6// Update tokens table where id
7Tokens.update(
8 { token: 'new token' },
9 { where: {id: idVar} }
10 ).then(tokens => {
11 console.log(tokens);
12 }).catch(err => console.log('error: ' + err));
1var Book = db.define(‘books’, {
2 title: {
3 type: Sequelize.STRING
4 },
5 pages: {
6 type: Sequelize.INTEGER
7 }
8})
9
10Book.update(
11 {title: req.body.title},
12 {where: req.params.bookId}
13 )
1const objectToUpdate = {
2title: 'Hello World',
3description: 'Hello World'
4}
5
6models.Locale.update(objectToUpdate, { where: { id: 2}})
7
8
1
2const objectToUpdate = {
3title: 'Hello World',
4description: 'Hello World'
5}
6
7models.Locale.findAll({ where: { title: 'Hello World'}}).then((result) => {
8 if(result){
9 // Result is array because we have used findAll. We can use findOne as well if you want one row and update that.
10 result[0].set(objectToUpdate);
11 result[0].save(); // This is a promise
12}
13})
14