Is it possible?
If not, where should I add this functionality in the source ccode?
"Releasing" only has meaning in the context of a pool. If you don't need a pool and you want to gracefully close all connections belonging to that pool, just use pool.end()
https://github.com/felixge/node-mysql/blob/1720920f7afc660d37430c35c7128b20f77735e3/lib/Pool.js#L152-L182
I use a pool, and then the app decide to close the pool.
For example:
var pool=db.createPool({})
for(var i=1;i<100;i++)
pool.query()
// Now I want to close all the connection of the pool
Hi @AminaG, in your example, since you are simply using pool.query for every operation, just calling pool.end would close them all. Extending your example:
var pool=db.createPool({})
for(var i=1;i<100;i++)
pool.query()
// Now I want to close all the connection of the pool
pool.end()
Hello,
Is it possible to wait that all waiting queries are completed before closing the pool please?
Regards,
S
Ended up with:
_shouldWeStopChild() {
return new Promise((resolve, reject) => {
setInterval(() => {
// Ensure all queries has been executed before exiting the script
let connectionQueue = this.Database.getCurrentConnection()._connectionQueue.length;
if(connectionQueue == 0) {
clearInterval(this._shouldWeStopChild);
debug('All queries has been completed.');
resolve();
} else {
debug('There are ' + connectionQueue + ' queries left');
}
}, 50);
});
}
Most helpful comment
Hi @AminaG, in your example, since you are simply using
pool.queryfor every operation, just callingpool.endwould close them all. Extending your example: