From 6b8eb5c80c72a164a374a0075569350e968f7774 Mon Sep 17 00:00:00 2001 From: Louis Orenstein Date: Fri, 23 Aug 2013 16:32:44 -0600 Subject: [PATCH] optional keepAlive configuration param allow users to specify an optional keepAlive parameter that will issue the query 'select 1' every keepAlive milliseconds so the schema-maintained connection does not get closed due to the MySQL server's idle connection timeout --- lib/mysql.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/mysql.js b/lib/mysql.js index 91b7437..87831b1 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -32,6 +32,12 @@ exports.initialize = function initializeSchema(schema, callback) { charset: s.collation.toUpperCase(), // Correct by docs despite seeming odd. supportBigNumbers: s.supportBigNumbers }); + + if (s.keepAlive) { + setInterval(function() { + schema.client.query('select 1'); + }, s.keepAlive); + } schema.client.on('error', function (err) { schema.emit('error', err);