【发布时间】:2018-12-04 18:13:12
【问题描述】:
我试图首先检查表中的值,如果存在,则删除另一个表中的一行并将新数据插入该表中。
我使用了一个带有 select、del() 和 insert 命令的事务
db.transaction(trx => {
return trx('users')
.where({ username: user.username })
.select('username')
.returning('username')
.then(retData => {
retUserName = retData[0];
db('profile')
.where({ username: user.username })
.del()
.then(retData => {
return trx
.insert(profileData)
.into('profile')
.returning('*');
});
})
.then(retData => {
res.json({ ProfileData: profileData });
})
.then(trx.commit)
.catch(trx.rollback);
}).catch(err => res.status(400).json('unable to create profile'));
我收到此错误未经处理的拒绝错误:事务查询已完成
但数据尚未添加到表中。
【问题讨论】: