【发布时间】:2018-02-24 00:43:01
【问题描述】:
在pg-promise 中,我需要触发一个内部事务,该事务可以在需要时回滚,不会导致调用事务在出错时回滚:
var db = pgp()(connection);
db.task( function (tk){
tk.method(/* Logic used to decide if I need to continue */)
.then( function(data){
if (!data) return;
tk.tx( function*(tx){
// Somewhere in here I need to fire another transaction that I don't care if it fails
// but I need things to roll back inside of it should it fail
// without cause this tx to fail
})
})
})
到目前为止,我所做的一切都只是导致外部事务 (tx) 在内部事务失败时回滚,而不是内部事务回滚并且外部事务继续执行后面的逻辑。如果子事务失败,是否有可靠的方法来导致不会导致tx 回滚的内部事务?
另外:当我尝试使用 Bluebird Promise.some(tx1, tx2) 时,这也会失败,因为失败会导致 tx 回滚,而另一个 tx# 也会失败并回滚。
【问题讨论】:
标签: node.js postgresql transactions pg-promise