node-red-node-mysql
Advanced tools
Comparing version 0.0.22 to 0.1.0
@@ -126,3 +126,19 @@ | ||
if (typeof msg.topic === 'string') { | ||
var bind = Array.isArray(msg.payload) ? msg.payload : []; | ||
//console.log("query:",msg.topic); | ||
var bind = []; | ||
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) { | ||
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.connection.query(msg.topic, bind, function(err, rows) { | ||
@@ -129,0 +145,0 @@ if (err) { |
{ | ||
"name": "node-red-node-mysql", | ||
"version": "0.0.22", | ||
"version": "0.1.0", | ||
"description": "A Node-RED node to read and write to a MySQL database", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -30,1 +30,24 @@ node-red-node-mysql | ||
<pre>mysqlReconnectTime: 30000,</pre></p> | ||
Preparing Queries | ||
----- | ||
```javascript | ||
msg.payload=[24, 'example-user']; | ||
msg.topic="INSERT INTO users (`userid`, `username`) VALUES (?, ?);" | ||
return msg; | ||
``` | ||
with named parameters: | ||
```javascript | ||
msg.payload={} | ||
msg.payload.userToChange=42; | ||
msg.payload.newUsername="example-user"; | ||
msg.topic="INSERT INTO users (`userid`, `username`) VALUES (:userToChange, :newUsername) ON DUPLICATE KEY UPDATE `username`=:newUsername;" | ||
return msg; | ||
``` | ||
Documentation | ||
----- | ||
<a href="https://www.npmjs.com/package/mysql" target="_new">Documentation</a> of the used Node.js 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
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
13999
172
53