-1
在下面的例子中,我從Sequelize docs獲得了關於事務的文檔,我不明白你爲什麼必須爲查詢添加return語句,以及在sequelize事務方法中。函數中的返回語句
function doTransaction() {
return sequelize.transaction(function (t) {
// chain all your queries here. make sure you return them.
return User.create({
firstName: 'Abraham',
lastName: 'Lincoln'
}, {transaction: t}).then(function (user) {
return user.setShooter({
firstName: 'John',
lastName: 'Boothe'
}, {transaction: t});
});
}).then(function (result) {
// Transaction has been committed
// result is whatever the result of the promise chain returned to the transaction callback
}).catch(function (err) {
// Transaction has been rolled back
// err is whatever rejected the promise chain returned to the transaction callback
});
}
嗯我不知道我明白你在說什麼,我將刪除我發佈的第二個示例,因爲它與第一個似乎無關 – lboyel
未能「返回」承諾意味着承諾鏈可以自由地繼續前進等候。如果你做*返回一些東西,那麼它有義務等待。 – tadman