I want to get the connection Id (threadId) when executing long query just in case the user at frontend (Vue.js) wants to cancel the query (in case query never ends...). So when the user clicks "Stop query", I would perform KILL (threadId) on Mysql..
I am using pooling with knew (client=mysql). I believe this is something trivial, but can please someone describe how can I access this. my backend (node.js) is set up differently - -- was made by a clever guy, who defined pools and connection as follows:
connection.connect(function(err) {
if (err) {
console.error('error connecting: ' + err.stack);
return;
}
console.log('connected as id ' + connection.threadId);
});
const knex = require("knex");
// Helpers -------------------------------------------------------------------
const connection = (user, password) =>
knex({
client: "mysql",
connection: {
multipleStatements: true,
host: process.env.MYSQL_IP,
port: process.env.MYSQL_PORT,
user,
password,
database: "",
dateStrings: true,
idleTimeoutMillis: -1
},
debug: true,
pool: {
min: 0,
max: 7
}
});
const knex_session = pool => (user, password) => {
if (pool[user] === undefined) {
pool[user] = connection(user, password);
}
return pool[user];
};
// Pool ----------------------------------------------------------------------
const connections = {};
// Exports -------------------------------------------------------------------
exports.admin = connection(
process.env.MYSQL_USERNAME,
process.env.MYSQL_PASSWORD
);
exports.client = knex_session(connections);
// ---------------------------------------------------------------------------
I am looking for a way to get the mysql threadId somehow - I imagine from the function(route). Orther options are aother call to mysql (SELECT CONNECTION_ID()) or by somehow extracting his data from request object (however, was not successful here as well). Than I would execute KILL QUERY (threadId) to make sure that the query does not hang and that I can display proper vue component to the user.