【问题标题】:Knex Error: Transaction query already complete, run with DEBUG=knex:tx for more infoKnex 错误:事务查询已完成,使用 DEBUG=knex:tx 运行以获取更多信息
【发布时间】:2022-09-23 10:36:19
【问题描述】:

这是我建立连接的方式

  const config = {
  \"client\": \"oracledb\",
  \"connection\": {
    \"host\": configurations.host,
    \"user\": configurations.auth.username,
    \"password\": configurations.auth.password,
    \"database\": configurations.database
  },
  \"useNullAsDefault\": true,
  \'debug\': true
};
const db = await knex(config).transaction();
return { db, Models: Models(db) };

在运行第一个查询并调用 db.commit()/db.rollback() 后,当我尝试运行更多查询时出现以下错误。

{
   method: \'first\',
   options: {},
   timeout: false,
   cancelOnTimeout: false,
   bindings: [ \'D000314-1\', \'2\', 1 ],
   __knexQueryUid: \'6BeVaYF9P_Zq9kq8pJJoZ\',
   sql: \'select * from (select * from \"ADMIN\".\"AGILE2PIMWEB_PACKAGES\" where \"ITEM_NUMBER\" = ? and \"NEW_REV\" = ? order by \"CREATED_ON\" desc) where rownum <= ?\'
 }
 Error: Transaction query already complete, run with DEBUG=knex:tx for more info
     at completedError (/GS-Integrator/pimweb-adapter/node_modules/knex/lib/execution/transaction.js:396:9)
     at /GS-Integrator/pimweb-adapter/node_modules/knex/lib/execution/transaction.js:362:24
     at new Promise (<anonymous>)
     at Client_Oracledb.trxClient.query (/GS-Integrator/pimweb-adapter/node_modules/knex/lib/execution/transaction.js:358:12)
     at Runner.query (/GS-Integrator/pimweb-adapter/node_modules/knex/lib/execution/runner.js:130:36)
     at ensureConnectionCallback (/GS-Integrator/pimweb-adapter/node_modules/knex/lib/execution/internal/ensure-connection-callback.js:13:17)
     at Runner.ensureConnection (/GS-Integrator/pimweb-adapter/node_modules/knex/lib/execution/runner.js:272:20)
     at processTicksAndRejections (node:internal/process/task_queues:96:5)
     at async Runner.run (/GS-Integrator/pimweb-adapter/node_modules/knex/lib/execution/runner.js:30:19)

有一个循环,我试图在循环的每次迭代中提交更改,但是单个事务不允许我这样做。此外,如果我为每次迭代创建一个新的 knex 连接,以前的连接不会被破坏,并且池最终会变满。任何遇到过类似问题并且知道解决此问题的人吗?

    标签: node.js node-modules knex.js


    【解决方案1】:

    您应该在循环之前启动事务(只有一个事务),然后在循环结束后提交事务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 2020-12-12
      • 2014-07-07
      • 2020-01-09
      • 1970-01-01
      相关资源
      最近更新 更多