有没有可能的方法向列中添加多个值?
现在我有一个评论栏,我有这个代码。
app.put('/addComment/:id', (req, res) => {
Posts.update({
comment: req.body.comment
},
{
where: {
id: req.params.id
}
}).then((post) => {
res.send(post)
}).catch((err) => {
console.log("err", err);
});
})
但是不是添加另一个值,它只是用 new 更新旧值,对解决我的问题的方法有什么建议吗?
最佳答案
您可以使用 concat 函数 sequelize
它将新值附加到列中。
const {fn, col } = models.sequelize
Posts.update({
members: fn('CONCAT', col("comment"), req.body.comment)
}, {
where: {
id: req.params.id
}
}).then(function() {
console.log("Value Appended");
});
关于node.js - 使用 nodeJS Sequelize 向 postgresql 添加多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62769593/