在将几条记录插入Postgres数据库后,使用knex的My Nodejs应用程序中断,出现以下错误:
未处理的拒绝错误
aborted at PendingOperation.abort (/mnt/c/Users/*********/node_modules/tarn/lib/PendingOperation.js:25:17)
at Promise.all.pendingAcquires.map.acquire (/mnt/c/Users/*********/node_modules/tarn/lib/Pool.js:190:23)
at Array.map (native)
at Promise.all.then.then (/mnt/c/Users/*********/node_modules/tarn/lib/Pool.js:189:34)
来自之前的活动:
at Client_PG.acquireConnection (/mnt/c/Users/*********/node_modules/knex/lib/client.js:335:34)
at /mnt/c/Users/*********/node_modules/knex/lib/transaction.js:191:41
来自之前的活动:
at Transaction.acquireConnection (/mnt/c/Users/*********/node_modules/knex/lib/transaction.js:190:34)
at new Transaction (/mnt/c/Users/*********/node_modules/knex/lib/transaction.js:68:53)
at Client_PG.transaction (/mnt/c/Users/*********/node_modules/knex/lib/client.js:159:12)
at Function.transaction (/mnt/c/Users/*********/node_modules/knex/lib/util/make-knex.js:75:21)
以下是破解的代码:
const writeOrdersToDB$ = (order: Order): Observable<Order> => {
const orderToInsert = cleanOrder(order);
return Observable.fromPromise(knex.transaction((trx: Transaction) => trx('order')
.insert(orderToInsert)
.returning('*')));
};