mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
let sqlite add extensions
This commit is contained in:
parent
85ddffb98f
commit
1b0f573f4e
@ -25,6 +25,8 @@ By it's very nature it is SQL injection... so *be careful* out there...
|
|||||||
|
|
||||||
Typically the returned payload will be an array of the result rows, (or an error).
|
Typically the returned payload will be an array of the result rows, (or an error).
|
||||||
|
|
||||||
|
You can load sqlite extensions by inputting a <code>msg.extension</code> property containing the full path and filename.
|
||||||
|
|
||||||
The reconnect timeout in milliseconds can be changed by adding a line to **settings.js**
|
The reconnect timeout in milliseconds can be changed by adding a line to **settings.js**
|
||||||
|
|
||||||
sqliteReconnectTime: 20000,
|
sqliteReconnectTime: 20000,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-sqlite",
|
"name": "node-red-node-sqlite",
|
||||||
"version": "0.3.2",
|
"version": "0.3.3",
|
||||||
"description": "A sqlite node for Node-RED",
|
"description": "A sqlite node for Node-RED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"sqlite3": "^4.0.2"
|
"sqlite3": "^4.0.2"
|
||||||
|
@ -77,6 +77,8 @@
|
|||||||
be sure to include $ on the parameter object key.</p>
|
be sure to include $ on the parameter object key.</p>
|
||||||
<p>Using any SQL Query, the result is returned in <code>msg.payload</code></p>
|
<p>Using any SQL Query, the result is returned in <code>msg.payload</code></p>
|
||||||
<p>Typically the returned payload will be an array of the result rows, (or an error).</p>
|
<p>Typically the returned payload will be an array of the result rows, (or an error).</p>
|
||||||
|
<p>You can load sqlite extensions by inputting a <code>msg.extension</code> property containing the full
|
||||||
|
path and filename.</p>
|
||||||
<p>The reconnect timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
|
<p>The reconnect timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
|
||||||
<pre>sqliteReconnectTime: 20000,</pre></p>
|
<pre>sqliteReconnectTime: 20000,</pre></p>
|
||||||
</script>
|
</script>
|
||||||
|
@ -43,12 +43,13 @@ module.exports = function(RED) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
node.status({});
|
node.status({});
|
||||||
|
|
||||||
if (this.mydbConfig) {
|
if (node.mydbConfig) {
|
||||||
this.mydbConfig.doConnect();
|
node.mydbConfig.doConnect();
|
||||||
node.status({fill:"green",shape:"dot",text:this.mydbConfig.mod});
|
node.status({fill:"green",shape:"dot",text:this.mydbConfig.mod});
|
||||||
var bind = [];
|
var bind = [];
|
||||||
node.on("input", function(msg) {
|
|
||||||
if (this.sqlquery == "msg.topic"){
|
var doQuery = function(msg) {
|
||||||
|
if (node.sqlquery == "msg.topic"){
|
||||||
if (typeof msg.topic === 'string') {
|
if (typeof msg.topic === 'string') {
|
||||||
bind = Array.isArray(msg.payload) ? msg.payload : [];
|
bind = Array.isArray(msg.payload) ? msg.payload : [];
|
||||||
node.mydbConfig.db.all(msg.topic, bind, function(err, row) {
|
node.mydbConfig.db.all(msg.topic, bind, function(err, row) {
|
||||||
@ -64,7 +65,7 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"red",shape:"dot",text:"msg.topic error"});
|
node.status({fill:"red",shape:"dot",text:"msg.topic error"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.sqlquery == "batch") {
|
if (node.sqlquery == "batch") {
|
||||||
if (typeof msg.topic === 'string') {
|
if (typeof msg.topic === 'string') {
|
||||||
node.mydbConfig.db.exec(msg.topic, function(err) {
|
node.mydbConfig.db.exec(msg.topic, function(err) {
|
||||||
if (err) { node.error(err,msg);}
|
if (err) { node.error(err,msg);}
|
||||||
@ -79,10 +80,10 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"red", shape:"dot",text:"msg.topic error"});
|
node.status({fill:"red", shape:"dot",text:"msg.topic error"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.sqlquery == "fixed"){
|
if (node.sqlquery == "fixed"){
|
||||||
if (typeof this.sql === 'string'){
|
if (typeof node.sql === 'string'){
|
||||||
bind = Array.isArray(msg.payload) ? msg.payload : [];
|
bind = Array.isArray(msg.payload) ? msg.payload : [];
|
||||||
node.mydbConfig.db.all(this.sql, bind, function(err, row) {
|
node.mydbConfig.db.all(node.sql, bind, function(err, row) {
|
||||||
if (err) { node.error(err,msg); }
|
if (err) { node.error(err,msg); }
|
||||||
else {
|
else {
|
||||||
msg.payload = row;
|
msg.payload = row;
|
||||||
@ -91,15 +92,15 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (this.sql === null || this.sql == ""){
|
if (node.sql === null || node.sql == ""){
|
||||||
node.error("SQL statement config not set up",msg);
|
node.error("SQL statement config not set up",msg);
|
||||||
node.status({fill:"red",shape:"dot",text:"SQL config not set up"});
|
node.status({fill:"red",shape:"dot",text:"SQL config not set up"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.sqlquery == "prepared"){
|
if (node.sqlquery == "prepared"){
|
||||||
if (typeof this.sql === 'string' && typeof msg.params !== "undefined" && typeof msg.params === "object"){
|
if (typeof node.sql === 'string' && typeof msg.params !== "undefined" && typeof msg.params === "object"){
|
||||||
node.mydbConfig.db.all(this.sql, msg.params, function(err, row) {
|
node.mydbConfig.db.all(node.sql, msg.params, function(err, row) {
|
||||||
if (err) { node.error(err,msg); }
|
if (err) { node.error(err,msg); }
|
||||||
else {
|
else {
|
||||||
msg.payload = row;
|
msg.payload = row;
|
||||||
@ -108,7 +109,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (this.sql === null || this.sql == ""){
|
if (node.sql === null || node.sql == ""){
|
||||||
node.error("Prepared statement config not set up",msg);
|
node.error("Prepared statement config not set up",msg);
|
||||||
node.status({fill:"red",shape:"dot",text:"Prepared statement not set up"});
|
node.status({fill:"red",shape:"dot",text:"Prepared statement not set up"});
|
||||||
}
|
}
|
||||||
@ -122,10 +123,20 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
node.on("input", function(msg) {
|
||||||
|
if (msg.hasOwnProperty("extension")) {
|
||||||
|
node.mydbConfig.db.loadExtension(msg.extension, function(err) {
|
||||||
|
if (err) { node.error(err,msg); }
|
||||||
|
else { doQuery(msg); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else { doQuery(msg); }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.error("Sqlite database not configured");
|
node.error("Sqlite database not configured");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("sqlite",SqliteNodeIn);
|
RED.nodes.registerType("sqlite",SqliteNodeIn);
|
||||||
|
Loading…
Reference in New Issue
Block a user