序列化推送值

Sequelize push values

如何在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'
})

(抱歉英语不好)

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

假设您在请求正文中对所有参数进行了正确格式化,您可以像这样更新任何 table 值:

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

用 es6 你可以在一个字符串中写变量 `:

table.find({where: {id: 1}}).then(function(result) {
    result.name = `${result.name}test`;
    result.save();
});

更多信息在这里: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings