CodeFoodPixels / node-promise-mysql

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

Keep alive setting #2

Closed gajus closed 9 years ago

gajus commented 9 years ago

The nature of the promise API makes it impossible to use connection pool. There needs to be a way to keep the connection up for a continuously running service. promise-mysql wrapper does expose connection error handling (e.g. connection.on('error', fn)) that would normally be used to restore a dead connection.

I have proposed a (dirty) workaround for this on stack overflow, that involves making a simple query at a regular interval to keep the connection up:

setInterval(function () {
    db.query('SELECT 1');
}, 5000);

It almost feels that this should be part of promise-mysql.

CodeFoodPixels commented 9 years ago

I feel the other solution in that stack overflow thread is far cleaner. The one you suggested just feels like a hack.

Because promise-mysql handles the connection itself and doesn't expose the actual connection, I could easily handle it internally with the other solution.

CodeFoodPixels commented 9 years ago

Added in 84c7ed9fcc60a81cbc7fd3bdd6e1e4a87a1fcbe9