我正在尝试使用 Knex.js 更新表中的多个列
我曾尝试查看 Knex 文档以及在线中的建议,但到目前为止还没有找到任何可行的解决方案。
我的编码尝试:
const userUpdateHandler = (req,res,database)=>{
const { id } = req.params;
const { name, age } = req.body.formInput
database('users')
.where({ id })
.update({ name }).update({ age})
.then(resp => {
if (resp) {
res.json("success")
} else {
res.status(400).json('Not found')
}
})
.catch(err => res.status(400).json('error updating user'))
}
以上是我出于绝望而尝试过的内容,但我想做的是一次更新多个列。你能告诉我最好的方法吗?