mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
let sqlite add extensions
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user