Skip to content

Commit

Permalink
I added msg.query to the code to use predefined queries. (#19)
Browse files Browse the repository at this point in the history
msg.topic never used in the code but the readMe says it can hold SQL
queries. I replaced topic with query because topic used several time in
other nodes.

Co-authored-by: Mathias Rangel Wulff <m@rawu.dk>
  • Loading branch information
iamgaborgithub and mathiasrw committed Jan 2, 2020
1 parent e7cec71 commit 4e9ac45
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion node-red-contrib-alasql.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h4><a id="Returned_values_25"></a>Returned values</h4>
</code></pre>
<p>To manipulate output format please consult the use of <a href="https://github.com/agershun/alasql/wiki/Value"><code>VALUE OF</code></a>, <a href="https://github.com/agershun/alasql/wiki/MATRIX"><code>MATRIX OF</code></a>, <a href="https://github.com/agershun/alasql/wiki/COLUMN"><code>COLUMN OF</code></a>, <a href="https://github.com/agershun/alasql/wiki/ROW"><code>ROW OF</code></a>, and <a href="https://github.com/agershun/alasql/wiki/RECORDSET"><code>RECORDSET OF</code></a>.</p>
<h4><a id="Multiply_queries_36"></a>Multiply queries</h4>
<p>The <code>msg.topic</code> can hold several SQL queries separated by <code>;</code>. The returned value will be an array with the result from each typically returned payload.</p>
<p>The <code>msg.query</code> can hold several SQL queries separated by <code>;</code>. The returned value will be an array with the result from each typically returned payload.</p>
<h4><a id="Binding_parameters_41"></a>Binding parameters</h4>
<p>The <code>msg.payload</code> will be passed as a binded parameter. You can refer to the value by having <code>$0</code> in your SQL. If <code>msg.payload</code> is an array the first value will be <code>$0</code>, the second <code>$1</code> and so forth.</p>
<p>Please <a href="https://github.com/agershun/alasql/wiki/readme">consult the AlaSQL wiki</a> to undertand the flexible nature of the library.</p>
Expand Down
2 changes: 1 addition & 1 deletion node-red-contrib-alasql.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function (RED) {
var node = this;
node.query = config.query;
node.on("input", function (msg) {
var sql = this.query || msg.topic || 'SELECT * FROM ?';
var sql = this.query || msg.query || msg.topic || 'SELECT * FROM ?';
var bind = Array.isArray(msg.payload) ? msg.payload : [msg.payload];
alasql.promise(sql, bind)
.then(function (res) {
Expand Down

3 comments on commit 4e9ac45

@tmdoit-zz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here? Why the change? Why duplicating solution for the same use case? msg.query is doing same thing as msg.topic.
Now you can pass query via msq.topic and msq.query, additionaly you erased info in docs about msg.topic...
Please, undo this commit.

@mathiasrw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamgaborgithub any inputs regarding the feedback from @tmdoit ?

@mathiasrw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.