【发布时间】:2018-06-20 22:04:31
【问题描述】:
我有以下 Postgres 命令:
UPDATE users SET weightsovertime = weightsovertime || '{"weight":35,"date":"1/9/97"}'::jsonb where id = 20;
我想使用 Knex.js 等库将其转换为 SQL 查询生成器命令。
我试过这个:
postgres('users')
.where('id','=',id)
.update({
weightsovertime: weightsovertime +'||' + data + '::jsonb'
})
.returning('weightsovertime')
.then(response => {
res.json(response[0]);
})
.catch(err => res.status(400).json('unable to get entries'));
但它不起作用,我也尝试将“weightsovertime”括在引号中,但出现错误“无法获取条目”。
非常感谢任何帮助。
【问题讨论】:
-
如果您使用的是
pg-promise,那么为什么会出现这种复杂情况?这只是一个带有pg-promise的单行查询。 -
我试过 pg promise,但也没用
-
什么不起作用?如果您发布详细信息,那么您可以获得答案。
-
db.any('UPDATE users SET weightsovertime = weightsovertime || 'data'::jsonb where id = id);
标签: javascript postgresql knex.js pg-promise