Description
Would it be possible to add a connection method that would remove a queued (waiting) query from the connection queue? It would take a single parameter the query object as returned from connection.query()
and it would remove the query from the queue if the query is waiting. It should respond with one of three states: query removed, query currently executing (can't be removed), query not found (probably already executed).
A rough pseudocode what it would do (specific implementation details will need to be refined):
Connection.prototype.remove = function remove(query) {
var idx = this._protocol._queue.indexOf(queue)
if (idx < 0) {
return false; // Query not found
}
if (idx === 0) {
return false; // Query currently executing
}
this._protocol._queue.splice(idx, 1)
return true;
}
We need this feature for implementing timeouts in Knex.js, see this discussion knex/knex#4416 (comment). We don't want to hack the driver internals and we would prefer to use a supported feature. I'm willing to create a PR with the implementation if the feature would be accepted.
I'm filing a symmetric feature request to mysql2
driver sidorares/node-mysql2#1316. It would be good to implement it in a compatible way in both drivers.