-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnode-red-contrib-alasql.html
executable file
·73 lines (69 loc) · 3.88 KB
/
node-red-contrib-alasql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script type="text/x-red" data-template-name="alasql">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row" style="position: relative; margin-bottom: 0px;">
<label for="node-input-template"><i class="fa fa-file-code-o"></i> SQL query</span></label>
<input type="hidden" id="node-input-query" autofocus="autofocus">
</div>
<div class="form-row node-text-editor-row">
<div style="height:250px;" class="node-text-editor" id="node-input-query-editor"></div>
</div>
</script>
<script type="text/x-red" data-help-name="alasql">
A Node-RED node to use <a href="https://github.com/agershun/alasql" target="_blank">AlaSQL</a> for fast SQL based in-memory data processing for BI and ERP applications.</p>
<p>Especially useful when you have (many) different sources coming with data you want to join, filter and format with good'old SQL.</p>
<ul>
<li>
<p>A node's <code>SQL</code> parameter must hold a valid SQL query</p>
</li>
<li>
<p>The result will be returned in <code>msg.payload</code></p>
</li>
</ul>
<p>The typical query string can look like:</p>
<code>SELECT * FROM ? WHERE a > 10</code>
<h4><a id="Returned_values_25"></a>Returned values</h4>
<p>Typically the returned payload will be an array of objects:</p>
<pre><code class="language-json">[{name:'foo', age: 86}, {name:'bar', age:64}]
</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.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>
<h4><a id="Please_note_60"></a>Please note</h4>
<p>The library works in-memory as default - so all data are lost when Node-RED is restarted. Please consult <a href="https://github.com/agershun/alasql/wiki">the wiki</a> to read more about how to let data be persistent.</p>
</script>
<script type="text/javascript">
RED.nodes.registerType('alasql', {
category: 'advanced',
color: "#f7df8e",
inputs: 1,
outputs: 1,
defaults: {
name: {value: ''},
query: {value: 'SELECT * FROM ?'}
},
icon: "alasql.png",
label: function () {
return this.name || "alasql";
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function () {
this.editor = RED.editor.createEditor({
id: 'node-input-query-editor',
mode: 'ace/mode/sql',
value: $("#node-input-query").val()
});
},
oneditsave: function () {
$("#node-input-query").val(this.editor.getValue())
delete this.editor;
}
});
</script>