cormo
Advanced tools
Comparing version 1.2.4 to 1.3.0
@@ -17,2 +17,3 @@ /// <reference types="node" /> | ||
query_timeout?: number; | ||
max_lifetime?: number; | ||
replication?: { | ||
@@ -19,0 +20,0 @@ use_master_for_read?: boolean; |
@@ -798,2 +798,3 @@ "use strict"; | ||
this._client.getConnectionAsync = util_1.default.promisify(this._client.getConnection); | ||
this._setEvent(this._client, settings.max_lifetime); | ||
if (settings.replication) { | ||
@@ -820,2 +821,3 @@ this._read_clients = []; | ||
read_client.getConnectionAsync = util_1.default.promisify(read_client.getConnection); | ||
this._setEvent(read_client, settings.max_lifetime); | ||
this._read_clients.push(read_client); | ||
@@ -1283,2 +1285,16 @@ } | ||
} | ||
/** @internal */ | ||
_setEvent(client, max_lifetime) { | ||
if (!max_lifetime || max_lifetime <= 0) { | ||
return; | ||
} | ||
client.on('connection', (connection) => { | ||
connection._connected_ts = Date.now(); | ||
}); | ||
client.on('release', (connection) => { | ||
if (Date.now() - connection._connected_ts >= max_lifetime) { | ||
connection.destroy(); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -1285,0 +1301,0 @@ exports.MySQLAdapter = MySQLAdapter; |
{ | ||
"name": "cormo", | ||
"description": "ORM framework for Node.js", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"keywords": [ | ||
@@ -70,3 +70,3 @@ "orm", | ||
}, | ||
"gitHead": "123a59eb57487e2d787c18d6598a7849d9f66abd" | ||
"gitHead": "92edd7795644ec121c90e3ac7ff3a1b13ceab753" | ||
} |
388091
10593