我有以下架构,
create table test (id int primary key ,x integer)
我想用 old + new value 更新重复 column x
喜欢跟随sequelize-nodejs的原始查询 .
INSERT INTO test (id,x) VALUES (1,5) ON DUPLICATE KEY UPDATE x=x+VALUES(x);
你可以这样做:
步骤1:查找实例步骤2:使用旧的更新值
和
第3步:保存实例
Table.find({ where: { //condition } }) .then(entity => { if (entity) { entity.val += req.body.newVal; return entity.save() .then(() => { res.status(200); }) .catch(validationError(res)); } else { return res.status(404).end(); } })
1 回答
你可以这样做:
和