mysql faster/tidier closing of pool if never connected.

This commit is contained in:
Dave Conway-Jones 2022-07-11 14:39:16 +01:00
parent 3ffd3f9fad
commit 0b3b918528
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 16 additions and 9 deletions

View File

@ -65,19 +65,26 @@ module.exports = function(RED) {
});
}
this.connect = function() {
if (!this.connected && !this.connecting) {
node.connect = function() {
if (!node.connected && !node.connecting) {
doConnect();
}
}
this.on('close', function(done) {
if (this.tick) { clearTimeout(this.tick); }
if (this.check) { clearInterval(this.check); }
node.connected = false;
node.on('close', function(done) {
if (node.tick) { clearTimeout(node.tick); }
if (node.check) { clearInterval(node.check); }
// node.connection.release();
node.emit("state"," ");
node.pool.end(function(err) { done(); });
if (node.connected) {
node.connected = false;
node.pool.end(function(err) { done(); });
}
else {
delete node.pool;
done();
}
});
}
RED.nodes.registerType("MySQLdatabase",MySQLNode, {
@ -173,7 +180,7 @@ module.exports = function(RED) {
});
}
else {
this.error(RED._("mysql.errors.notconfigured"));
node.error(RED._("mysql.errors.notconfigured"));
}
}
RED.nodes.registerType("mysql",MysqlDBNodeIn);

View File

@ -1,6 +1,6 @@
{
"name": "node-red-node-mysql",
"version": "1.0.1",
"version": "1.0.2",
"description": "A Node-RED node to read and write to a MySQL database",
"dependencies": {
"mysql2": "^2.3.3"