CodeFoodPixels / node-promise-mysql

A wrapper for mysqljs/mysql that wraps function calls with Bluebird promises.
MIT License
338 stars 64 forks source link

Connection is not getting close #99

Closed sarthakshah7 closed 5 years ago

sarthakshah7 commented 5 years ago

I am using promise-mysql version 3.3.1 in a project. I have following the same practices as it was suggested on npm package page. var mysql = require('promise-mysql');

mysql.createConnection({ host: 'localhost', user: 'sauron', password: 'theonetruering', database: 'mordor' }).then(function(conn){ // do stuff with conn let result = conn.query('select * from table_name'); conn.end(); return result; });

But then also connection remains open. when I checked in mysql console using "SHOW FULL PROCESSLIST;" it shows that the connection to db exist with COMMAND : "Sleep" and STATE : ''. I want to close the connection but it is not working as it says. Please let me know for the solution of the same problem.

CodeFoodPixels commented 5 years ago

Can you try it with the conn.end() in a .then after the query?

Like this:

let connection;

...).then(function(conn){
connection = conn;
return conn.query('select * from table_name');
}).then(() => {
connection.end();
})
sarthakshah7 commented 5 years ago

Thanks @lukeb-uk .

``