Skip to content

Commit

Permalink
Merge 5c36b4b into 0d1a41f
Browse files Browse the repository at this point in the history
  • Loading branch information
ericdum committed May 18, 2021
2 parents 0d1a41f + 5c36b4b commit ee2626d
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions storage/mysql/68-mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = function(RED) {
});
}

// connection test
node.pool.getConnection(function(err, connection) {
node.connecting = false;
if (err) {
Expand All @@ -56,25 +57,10 @@ module.exports = function(RED) {
node.tick = setTimeout(doConnect, reconnect);
}
else {
node.connection = connection;
node.connected = true;
node.emit("state","connected");
node.connection.on('error', function(err) {
node.connected = false;
node.connection.release();
node.emit("state",err.code);
if (err.code === 'PROTOCOL_CONNECTION_LOST') {
doConnect(); // silently reconnect...
}
else if (err.code === 'ECONNRESET') {
doConnect(); // silently reconnect...
}
else {
node.error(err);
doConnect();
}
});
if (!node.check) { node.check = setInterval(checkVer, 290000); }
connection.release();
}
});
}
Expand All @@ -89,7 +75,6 @@ module.exports = function(RED) {
if (this.tick) { clearTimeout(this.tick); }
if (this.check) { clearInterval(this.check); }
node.connected = false;
// node.connection.release();
node.emit("state"," ");
node.pool.end(function(err) { done(); });
});
Expand Down Expand Up @@ -117,8 +102,6 @@ module.exports = function(RED) {
if (info === "connecting") { node.status({fill:"grey",shape:"ring",text:info}); }
else if (info === "connected") { node.status({fill:"green",shape:"dot",text:info}); }
else {
if (info === "ECONNREFUSED") { info = "connection refused"; }
if (info === "PROTOCOL_CONNECTION_LOST") { info = "connection lost"; }
node.status({fill:"red",shape:"ring",text:info});
}
});
Expand All @@ -132,7 +115,7 @@ module.exports = function(RED) {
if (Array.isArray(msg.payload)) { bind = msg.payload; }
else if (typeof msg.payload === 'object' && msg.payload !== null) {
bind = msg.payload;
node.mydbConfig.connection.config.queryFormat = function(query, values) {
node.mydbConfig.pool.config.queryFormat = function(query, values) {
if (!values) {
return query;
}
Expand All @@ -144,7 +127,7 @@ module.exports = function(RED) {
}.bind(this));
};
}
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
node.mydbConfig.pool.query(msg.topic, bind, function(err, rows) {
if (err) {
status = {fill:"red",shape:"ring",text:"Error: "+err.code};
node.status(status);
Expand Down

0 comments on commit ee2626d

Please sign in to comment.