Skip to content

Commit

Permalink
Use a connection pool to automatically reconnect to MySQL when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed Jul 25, 2016
1 parent f6b7ffb commit 0291c7c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ var mysql = require('mysql');
var config = require('./config');

exports.connect = function(done) {
var db = mysql.createConnection(config.mysql);
db.connect();
var pool = mysql.createPool(Object.assign({
connectionLimit : 2,
}, config.mysql));

require('./migrations').doMigrations(db, function(err) {
require('./migrations').doMigrations(pool, function(err) {
if (err) {
done(err);
} else {
done(null, db);
done(null, pool);
}
});
};

0 comments on commit 0291c7c

Please sign in to comment.