knex-serverless-mysql
knex-serverless-mysql copied to clipboard
Provide a way to close the connection
Firstly, thanks a lot for this plugin!
I tried it, and I think, the plugin should use default knex methods to close the connection. Right now calling knex.destroy() does nothing, and the connection hangs.
I've come up with this code to close the connection:
const mysql = require('serverless-mysql')({ config });
const knexServerlessMysql = require('knex-serverless-mysql');
const knexInstance = Knex({
mysql,
client: knexServerlessMysql,
} as any);
// ...
const originalDestroy = (knexInstance as any).context.destroy;
(knexInstance as any).context.destroy = async () => {
if (knexInstance) {
await originalDestroy.apply(knexInstance);
}
if (mysql) {
await mysql.end();
mysql.quit();
}
};
Is there any way this could be integrated within knex-serverless-mysql?
Hey,
Great feedback. Feel free to submit a PR with the change and I'll review it in depth.
this is working already or not?