express-mysql-pool
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -12,20 +12,19 @@ var _pool, // Pool singleton | ||
return function(req, res, next) { | ||
var poolConn = null; | ||
// Returning cached connection from a pool, caching is on request level | ||
if(req.__expressMysqlConnectionCache__) { | ||
req.getConnection = function (callback) { | ||
pollConn = req.__expressMysqlConnectionCache__; | ||
callback(null, poolConn); | ||
callback(null, req.__expressMysqlConnectionCache__); | ||
} | ||
closeConnection(res, req.__expressMysqlConnectionCache__); | ||
}else { | ||
// Getting connection from a pool | ||
req.getConnection = function (callback) { | ||
_pool.getConnection(function (err, connection) { | ||
_pool.getConnection(function (err, poolConn) { | ||
if (err) return callback(err); | ||
poolConn = req.__expressMysqlConnectionCache__ = connection; | ||
req.__expressMysqlConnectionCache__ = poolConn; | ||
callback(null, poolConn); | ||
closeConnection(res, poolConn); | ||
}); | ||
} | ||
} | ||
closeConnection(res, poolConn); | ||
next(); | ||
@@ -32,0 +31,0 @@ }; |
{ | ||
"name": "express-mysql-pool", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "express-mysql-connection middleware (pooling connection)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3989
39