mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
mysql - ensure connection released back to pool more often
and try to ensure status is shown more correctly on error.
This commit is contained in:
parent
ea3ed9ff5e
commit
705dd1ffc1
@ -19,8 +19,8 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
function checkVer() {
|
function checkVer() {
|
||||||
node.connection.query("SELECT version();", [], function(err, rows) {
|
node.connection.query("SELECT version();", [], function(err, rows) {
|
||||||
if (err) {
|
|
||||||
node.connection.release();
|
node.connection.release();
|
||||||
|
if (err) {
|
||||||
node.error(err);
|
node.error(err);
|
||||||
node.status({fill:"red",shape:"ring",text:"Bad Ping"});
|
node.status({fill:"red",shape:"ring",text:"Bad Ping"});
|
||||||
doConnect();
|
doConnect();
|
||||||
@ -86,6 +86,7 @@ module.exports = function(RED) {
|
|||||||
if (this.tick) { clearTimeout(this.tick); }
|
if (this.tick) { clearTimeout(this.tick); }
|
||||||
if (this.check) { clearInterval(this.check); }
|
if (this.check) { clearInterval(this.check); }
|
||||||
node.connected = false;
|
node.connected = false;
|
||||||
|
node.connection.release();
|
||||||
node.emit("state"," ");
|
node.emit("state"," ");
|
||||||
node.pool.end(function (err) { done(); });
|
node.pool.end(function (err) { done(); });
|
||||||
});
|
});
|
||||||
@ -124,8 +125,9 @@ module.exports = function(RED) {
|
|||||||
var bind = Array.isArray(msg.payload) ? msg.payload : [];
|
var bind = Array.isArray(msg.payload) ? msg.payload : [];
|
||||||
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
|
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
status = {fill:"red",shape:"ring",text:"Error: "+err.code};
|
||||||
|
node.status(status);
|
||||||
node.error(err,msg);
|
node.error(err,msg);
|
||||||
status = {fill:"red",shape:"ring",text:"Error"};
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (rows.constructor.name === "OkPacket") {
|
if (rows.constructor.name === "OkPacket") {
|
||||||
@ -134,6 +136,7 @@ module.exports = function(RED) {
|
|||||||
else { msg.payload = rows; }
|
else { msg.payload = rows; }
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
status = {fill:"green",shape:"dot",text:"OK"};
|
status = {fill:"green",shape:"dot",text:"OK"};
|
||||||
|
node.status(status);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-mysql",
|
"name": "node-red-node-mysql",
|
||||||
"version": "0.0.20",
|
"version": "0.0.21",
|
||||||
"description": "A Node-RED node to read and write to a MySQL database",
|
"description": "A Node-RED node to read and write to a MySQL database",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mysql": "^2.18.1"
|
"mysql": "^2.18.1"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user