Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-mysql-connection

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-mysql-connection - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

38

lib/express-mysql-connection.js

@@ -7,3 +7,2 @@ var _mysql,

module.exports = function (mysql, dbConfig, strategy) {

@@ -27,3 +26,2 @@

handleDisconnect(dbConfig);
// single connection strategy
// 单链接策略时返回的中间件 * * * * * * * * * * * * * * * *

@@ -41,11 +39,9 @@ _middlewareFn = function(req, res, next) {

_pool = _mysql.createPool(dbConfig);
// pool
// 连接池策略时返回的中间件 * * * * * * * * * * * * * * * *
_middlewareFn = 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, requestConn);
callback(null, req.__expressMysqlConnectionCache__);
closeConnection(res, req.__expressMysqlConnectionCache__);
}

@@ -55,10 +51,10 @@ }else {

req.getConnection = function (callback) {
_pool.getConnection(function (err, connection) {
_pool.getConnection(function (err, poolConn) {
if (err) return callback(err);
poolConnection = connection;
callback(null, poolConnection);
req.__expressMysqlConnectionCache__ = poolConn;
callback(null, poolConn);
closeConnection(res, poolConn);
});
}
}
closeConnection(res, poolConn);
next();

@@ -68,15 +64,13 @@ }

case 'request':
// request
// 请求时创建连接,请求结束后自动释放 * * * * * * * * * * * *
_middlewareFn = function(req, res, next) {
var requestConn = null;
// Returning cached connection, caching is on request level
if(req.__expressMysqlConnectionCache__) {
req.getConnection = function(callback) {
requestConn = req.__expressMysqlConnectionCache__;
callback(null, requestConn);
callback(null, req.__expressMysqlConnectionCache__);
}
closeConnection(res, null, req.__expressMysqlConnectionCache__);
}else {
req.getConnection = function(callback) {
requestConn = _mysql.createConnection(dbConfig);
var requestConn = _mysql.createConnection(dbConfig);
requestConn.connect(function (err) {

@@ -87,5 +81,5 @@ if (err) return callback(err);

});
closeConnection(res, null, requestConn);
}
}
closeConnection(res, null, requestConn);
next();

@@ -122,10 +116,14 @@ };

// Request closed unexpectedly.
res.on("close", closeHandler);
res.on("close", closeHandler);
// Finish
res.on("finish", closeHandler);
res.on("finish", closeHandler);
function closeHandler() {
if (poolConnection) poolConnection.release();
if (requestConnection) requestConnection.end();
if (poolConnection) {
poolConnection.release();
}
if (requestConnection) {
requestConnection.end();
}
}
}
{
"name": "express-mysql-connection",
"version": "1.1.0",
"version": "1.1.1",
"description": "express-mysql-connection middleware",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc