与@Mikael达成一致,您不需要
new Promise
,但我认为你也需要
return knex.transaction(
,以便在完成其他处理之前完成事务处理功能?
function process(params){
return knex.transaction(function(trx){
return insertRows(rows, trx)
}).then(function (result){
return insertRows(rows2,trx)
}).then(function (result){
return updateRows(rows3,trx)
});
}
因为你没有
return knex.transaction()
,此操作将与调用方的序列“断开连接”,并异步运行。
你的
return Promise.resolve() //this is probably wrong
很好。您将在
else
,就像在
if
函数的一部分。因为该(子)函数仅在
Promise
。。。
.then
,实际上可以省略
其他的
子句,因为
。然后
语句自动将同步函数返回值转换为已解析的承诺。