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);
}
}