2015-10-06 51 views
0

如何在Sequelize中創建推送值,類比SQL請求UPDATE table SET fields = fields + 'test'續集推送值

例子:

table.find({where: {id: 1}}).then(function(result) { 
    console.log(result.name); //returned 'abc' 
}) 

//actions (+ 'test') 

table.find({where: {id: 1}}).then(function(result) { 
    console.log(result.name); //returned 'abctest' 
}) 

(對不起,我英文不好)

回答

0
table.find({where: {id: 1}}).then(function(result) { 
    result.name = result.name + 'test'; 
    result.save(); 
}) 
0

假如你有良好的格式化的請求的所有參數可以更新任何像這樣的表值:

table.update(req.body, 
      {where: { id: 1 } } 
     ) 
     .then(() => { 
      //some other stuff 
     }) 
     .catch(app.error);