node-red-node-mysql
Advanced tools
Comparing version 0.3.0 to 1.0.0-beta
@@ -115,61 +115,37 @@ | ||
//console.log("query:",msg.topic); | ||
var bind = []; | ||
if (Array.isArray(msg.payload)) { | ||
bind = msg.payload; | ||
node.mydbConfig.pool.on('acquire', function(connection) { | ||
connection.config.queryFormat = null; | ||
}); | ||
} | ||
else if (typeof msg.payload === 'object' && msg.payload !== null) { | ||
bind = msg.payload; | ||
node.mydbConfig.pool.on('acquire', function(connection) { | ||
connection.config.queryFormat = function(query, values) { | ||
if (!values) { | ||
return query; | ||
} | ||
return query.replace(/\:(\w+)/g, function(txt, key) { | ||
if (values.hasOwnProperty(key)) { | ||
return this.escape(values[key]); | ||
} | ||
return txt; | ||
}.bind(this)); | ||
}; | ||
}); | ||
} | ||
node.mydbConfig.pool.query(msg.topic, bind, function(err, rows) { | ||
node.mydbConfig.pool.getConnection(function (err, conn) { | ||
if (err) { | ||
status = {fill:"red",shape:"ring",text:RED._("mysql.status.error")+": "+err.code}; | ||
conn.release() | ||
status = { fill: "red", shape: "ring", text: RED._("mysql.status.error") + ": " + err.code }; | ||
node.status(status); | ||
node.error(err,msg); | ||
node.error(err, msg); | ||
if (done) { done(); } | ||
return | ||
} | ||
else { | ||
// if (rows.constructor.name === "OkPacket") { | ||
// msg.payload = JSON.parse(JSON.stringify(rows)); | ||
// } | ||
// else if (rows.constructor.name === "Array") { | ||
// if (rows[0] && rows[0].constructor.name === "RowDataPacket") { | ||
// msg.payload = rows.map(v => Object.assign({}, v)); | ||
// } | ||
// else if (rows[0] && rows[0].constructor.name === "Array") { | ||
// if (rows[0][0] && rows[0][0].constructor.name === "RowDataPacket") { | ||
// msg.payload = rows.map(function(v) { | ||
// if (!Array.isArray(v)) { return v; } | ||
// v.map(w => Object.assign({}, w)) | ||
// }); | ||
// } | ||
// else { msg.payload = rows; } | ||
// } | ||
// else { msg.payload = rows; } | ||
// } | ||
// else { msg.payload = rows; } | ||
msg.payload = rows; | ||
send(msg); | ||
status = {fill:"green",shape:"dot",text:RED._("mysql.status.ok")}; | ||
node.status(status); | ||
var bind = []; | ||
if (Array.isArray(msg.payload)) { | ||
bind = msg.payload; | ||
} | ||
if (done) { done(); } | ||
// if (node.mydbConfig.pool._freeConnections.indexOf(node.mydbConfig.connection) === -1) { | ||
// node.mydbConfig.connection.release(); | ||
// } | ||
}); | ||
else if (typeof msg.payload === 'object' && msg.payload !== null) { | ||
bind = msg.payload; | ||
} | ||
conn.config.queryFormat = Array.isArray(msg.payload) ? null : customQueryFormat | ||
conn.query(msg.topic, bind, function (err, rows) { | ||
conn.release() | ||
if (err) { | ||
status = { fill: "red", shape: "ring", text: RED._("mysql.status.error") + ": " + err.code }; | ||
node.status(status); | ||
node.error(err, msg); | ||
} | ||
else { | ||
msg.payload = rows; | ||
send(msg); | ||
status = { fill: "green", shape: "dot", text: RED._("mysql.status.ok") }; | ||
node.status(status); | ||
} | ||
if (done) { done(); } | ||
}); | ||
}) | ||
} | ||
@@ -204,1 +180,13 @@ else { | ||
} | ||
function customQueryFormat(query, values) { | ||
if (!values) { | ||
return query; | ||
} | ||
return query.replace(/\:(\w+)/g, function(txt, key) { | ||
if (values.hasOwnProperty(key)) { | ||
return this.escape(values[key]); | ||
} | ||
return txt; | ||
}.bind(this)); | ||
} |
{ | ||
"name": "node-red-node-mysql", | ||
"version": "0.3.0", | ||
"version": "1.0.0-beta", | ||
"description": "A Node-RED node to read and write to a MySQL database", | ||
"dependencies": { | ||
"mysql": "^2.18.1" | ||
"mysql2": "^2.3.3" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/node-red/node-red-nodes/tree/master/storage/mysql" | ||
"url": "https://github.com/node-red/node-red-nodes.git", | ||
"directory": "tree/master/storage/mysql" | ||
}, | ||
@@ -12,0 +13,0 @@ "license": "Apache-2.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18111
219
+ Addedmysql2@^2.3.3
+ Addeddenque@2.1.0(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedlong@4.0.0(transitive)
+ Addedlru-cache@6.0.07.18.3(transitive)
+ Addedmysql2@2.3.3(transitive)
+ Addednamed-placeholders@1.1.3(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedseq-queue@0.0.5(transitive)
+ Addedsqlstring@2.3.3(transitive)
+ Addedyallist@4.0.0(transitive)
- Removedmysql@^2.18.1
- Removedbignumber.js@9.0.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedmysql@2.18.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.7(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsqlstring@2.3.1(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)