node.js - 使用 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);
});
})
但是,它不是添加另一个值,而是用 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");
});
推荐阅读
- kubernetes - 印花布`套接字错误:绑定:Gitlab kube runner 作业后地址不可用`
- reactjs - 在 Material UI 自动完成上显示一个值(而不是标签)
- terraform - Terraform v0.13 - 检查是否提供了密码或密码,如果没有,则使用随机生成的密码
- google-apps-script - 如何使用脚本从谷歌工作表中删除除最后 2 行之外的所有行?
- list - 用户更改 word 文档内容属性数据时更新 SharePoint 列表
- gradle - Intellij Idea - 如何将其他 gradle 项目添加为依赖项以立即反映依赖项目中的更改
- json - 在雪花中粉碎嵌套的 JSON
- r - 在 R 中使用 fitTMB() 疏浚预设置 glmmTMB 时出错
- wmic - Get-WmiObject Win32_BaseBoard 为空
- python - 如何训练具有多个输入的 Keras 模型?