We are using node-mysql and I'm exposing createPool of mysql where from any file, we can require the database file and obtain a connection like this
var db = ("./database");
db(function(err, connection) {
//use connection to do stuff
}
I noticed that people don't always remember to call connection.end()
that would return the connection to the pool and then we hit the limit..
How can I design the acquiring of the connection so that no matter when they decide to terminate the callback function that the connection.end() is called? I can't figure out a way to make a single place where we can do this so developers are only concerned with getting the connection..