I am using the following code to make a knex connection, but frequently the error occurred
Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
Can anyone please suggest the solution for this issue?
var knexConn = reqKnex({ client: pClient, native: false, connection: pConn, searchPath: pSearchPath, pool: { max: 7, min: 3, acquireTimeout: 60 * 1000 } }); function getTransactionScope(pKnex, callback) { try { pKnex.transaction(function(trx) { return callback(trx); }); } catch (error) { console.log(error); } } function ExecuteSQLQuery(pTranDB, pTrx, pQuery, pCallback) { try { var query = pTranDB.raw(pQuery); if (pTrx) { query = query.transacting(pTrx); } query.then(function(res, error) { try { if (error) { console.log(error); } else { return pCallback(res, error); } } catch (error) { console.log(error); } }).catch(function(error) { return pCallback(null, error); }); } catch (error) { console.log(error); } } function Commit(pTrx, pIsCommit) { try { if (pIsCommit) { pTrx.commit(); } else { pTrx.rollback(); } } catch (error) { console.log(error); } }
How do I debug? # Knex is beginning to make use of the debug module internally, so you can set the DEBUG environment variable to knex:* to see all debugging, or select individual namespaces DEBUG=knex:query,knex:tx to constrain a bit.
Knex is a SQL query builder, mainly used for Node. js applications with built in model schema creation, table migrations, connection pooling and seeding.
Knex is a technique that is used to build queries. It supports various databases like Postgres, MySQL, SQLite, Oracle, and some others as well. It provides both callbacks and promise interface. It provides connection pooling and standardized responses.
I solved this problem with these versions:
"knex": "^0.21.1", "objection": "^2.1.3", "pg": "^8.0.3"
I had this issue recently, and I had just updated to Node v14.2.0
This version seems to have a breaking change to knex. Luckily I have NVM so I switch to another version (v12.16.3) and this solved the issue.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With