From 43c6bdb95ad71b9f7e691de467e8634e053c4f97 Mon Sep 17 00:00:00 2001 From: Kris Daniels Date: Sat, 21 Dec 2013 09:23:46 +0100 Subject: [PATCH] removed script editor from node config added support for script in msg.payload added support for query parameters in msg.queryParameters --- storage/postgres/110-postgres.html | 83 +++++------------------------- storage/postgres/110-postgres.js | 9 ++-- 2 files changed, 17 insertions(+), 75 deletions(-) diff --git a/storage/postgres/110-postgres.html b/storage/postgres/110-postgres.html index 09a887a8..033cc990 100644 --- a/storage/postgres/110-postgres.html +++ b/storage/postgres/110-postgres.html @@ -60,43 +60,18 @@
- - -
-
-
- - + + +
@@ -107,8 +82,7 @@ limit 1

defaults: { postgresdb: { type:"postgresdb",required:true}, name: {value:""}, - sqlquery: {value:"",required:true}, - outputs: {value:0} + output: {value:false} }, inputs:1, outputs:0, @@ -121,47 +95,14 @@ limit 1

return this.name?"node_label_italic":""; }, oneditprepare: function() { - $( "#node-input-outputs" ).spinner({ - min:0, - max:1 - }); - $( "#node-input-outputs" ).spinner( "value", this.outputs ); + $( "#node-input-output" ).prop( "checked", this.output ); + $("#node-input-name").focus(); - function functionDialogResize(ev,ui) { - $("#node-input-sqlquery-editor").css("height",(ui.size.height-235)+"px"); - }; - - $( "#dialog" ).on("dialogresize", functionDialogResize); - $( "#dialog" ).one("dialogopen", function(ev) { - var size = $( "#dialog" ).dialog('option','sizeCache-function'); - if (size) { - functionDialogResize(null,{size:size}); - } - }); - $( "#dialog" ).one("dialogclose", function(ev,ui) { - var height = $( "#dialog" ).dialog('option','height'); - $( "#dialog" ).off("dialogresize",functionDialogResize); - }); - var that = this; - require(["orion/editor/edit"], function(edit) { - that.editor = edit({ - parent:document.getElementById('node-input-sqlquery-editor'), - lang:"sql", - contents: $("#node-input-sqlquery").val() - }); - RED.library.create({ - url:"storage", // where to get the data from - type:"postgres", // the type of object the library is for - editor:that.editor, // the field name the main text body goes to - fields:['name','outputs'] - }); - $("#node-input-name").focus(); - - }); }, oneditsave: function() { - $("#node-input-sqlquery").val(this.editor.getText()) + var hasOutput = $( "#node-input-output" ).prop( "checked" ); + this.outputs = hasOutput ? 1: 0; delete this.editor; } }); diff --git a/storage/postgres/110-postgres.js b/storage/postgres/110-postgres.js index 36e02b05..edd42c88 100644 --- a/storage/postgres/110-postgres.js +++ b/storage/postgres/110-postgres.js @@ -36,7 +36,7 @@ function PostgresNode(n) { this.postgresdb = n.postgresdb; this.postgresConfig = RED.nodes.getNode(this.postgresdb); this.sqlquery = n.sqlquery; - this.outputs = n.outputs; + this.output = n.output; var node = this; if(this.postgresConfig) @@ -51,12 +51,13 @@ function PostgresNode(n) { else { node.on('input', function(msg){ - node.clientdb.query(node.sqlquery, - msg.payload, + if(!msg.queryParameters) msg.queryParameters={}; + node.clientdb.query(msg.payload, + msg.queryParameters, function (err, results) { if(err) { node.error(err); } else { - if(node.outputs>0) + if(node.output) { msg.payload = results.rows; node.send(msg);