diff --git a/storage/sqlite/README.md b/storage/sqlite/README.md index 9d2b8d3c..ae94aee3 100644 --- a/storage/sqlite/README.md +++ b/storage/sqlite/README.md @@ -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). +You can load sqlite extensions by inputting a msg.extension property containing the full path and filename. + The reconnect timeout in milliseconds can be changed by adding a line to **settings.js** sqliteReconnectTime: 20000, diff --git a/storage/sqlite/package.json b/storage/sqlite/package.json index 7bf56945..c671502c 100644 --- a/storage/sqlite/package.json +++ b/storage/sqlite/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-sqlite", - "version": "0.3.2", + "version": "0.3.3", "description": "A sqlite node for Node-RED", "dependencies": { "sqlite3": "^4.0.2" diff --git a/storage/sqlite/sqlite.html b/storage/sqlite/sqlite.html index 923f817c..28d5d966 100644 --- a/storage/sqlite/sqlite.html +++ b/storage/sqlite/sqlite.html @@ -77,6 +77,8 @@ be sure to include $ on the parameter object key.

Using any SQL Query, the result is returned in msg.payload

Typically the returned payload will be an array of the result rows, (or an error).

+

You can load sqlite extensions by inputting a msg.extension property containing the full + path and filename.

The reconnect timeout in milliseconds can be changed by adding a line to settings.js

sqliteReconnectTime: 20000,

diff --git a/storage/sqlite/sqlite.js b/storage/sqlite/sqlite.js index c5ec8e0b..39c0bc68 100644 --- a/storage/sqlite/sqlite.js +++ b/storage/sqlite/sqlite.js @@ -43,12 +43,13 @@ module.exports = function(RED) { var node = this; node.status({}); - if (this.mydbConfig) { - this.mydbConfig.doConnect(); + if (node.mydbConfig) { + node.mydbConfig.doConnect(); node.status({fill:"green",shape:"dot",text:this.mydbConfig.mod}); 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') { bind = Array.isArray(msg.payload) ? msg.payload : []; 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"}); } } - if (this.sqlquery == "batch") { + if (node.sqlquery == "batch") { if (typeof msg.topic === 'string') { node.mydbConfig.db.exec(msg.topic, function(err) { if (err) { node.error(err,msg);} @@ -79,10 +80,10 @@ module.exports = function(RED) { node.status({fill:"red", shape:"dot",text:"msg.topic error"}); } } - if (this.sqlquery == "fixed"){ - if (typeof this.sql === 'string'){ + if (node.sqlquery == "fixed"){ + if (typeof node.sql === 'string'){ 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); } else { msg.payload = row; @@ -91,15 +92,15 @@ module.exports = function(RED) { }); } else{ - if (this.sql === null || this.sql == ""){ + if (node.sql === null || node.sql == ""){ node.error("SQL statement config not set up",msg); node.status({fill:"red",shape:"dot",text:"SQL config not set up"}); } } } - if (this.sqlquery == "prepared"){ - if (typeof this.sql === 'string' && typeof msg.params !== "undefined" && typeof msg.params === "object"){ - node.mydbConfig.db.all(this.sql, msg.params, function(err, row) { + if (node.sqlquery == "prepared"){ + if (typeof node.sql === 'string' && typeof msg.params !== "undefined" && typeof msg.params === "object"){ + node.mydbConfig.db.all(node.sql, msg.params, function(err, row) { if (err) { node.error(err,msg); } else { msg.payload = row; @@ -108,7 +109,7 @@ module.exports = function(RED) { }); } else{ - if (this.sql === null || this.sql == ""){ + if (node.sql === null || node.sql == ""){ node.error("Prepared statement config not set up",msg); 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 { - this.error("Sqlite database not configured"); + node.error("Sqlite database not configured"); } } RED.nodes.registerType("sqlite",SqliteNodeIn);