使用 nodeJS Sequelize 向 postgresql 添加多个值



有没有办法向列添加多个值? 现在我有一个评论列,我有这个代码.

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);
});
})

但是,它不是添加另一个值,而是用新的值更新旧的值,关于解决我问题的方法的任何建议?

您可以使用 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");
});

最新更新