forked from andreabadesso/node-red-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres.html
More file actions
459 lines (428 loc) · 18.6 KB
/
postgres.html
File metadata and controls
459 lines (428 loc) · 18.6 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<!--
Copyright 2013 Kris Daniels.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="postgresdb">
<p>Connection can be set up by either defining a full or partial connection string, or specific connection parameters</p>
<div class="form-row">
<label for="node-config-input-connectionstring"><i class="fa fa-bookmark"></i> Connection String</label>
<input class="input-append-left" type="text" id="node-config-input-connectionstring" >
</div>
<div class="form-row">
<label for="node-config-input-hostname"><i class="fa fa-bookmark"></i> Host</label>
<input class="input-append-left" type="text" id="node-config-input-hostname" placeholder="localhost" style="width: 40%;" >
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; "> Port</label>
<input type="text" id="node-config-input-port" placeholder="5432" style="width:45px">
</div>
<div class="form-row">
<label for="node-config-input-db"><i class="fa fa-briefcase"></i> Database</label>
<input type="text" id="node-config-input-db" placeholder="test">
</div>
<div class="form-row">
<label for="node-config-input-user"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-config-input-user" placeholder="postgres">
</div>
<div class="form-row">
<label for="node-config-input-password"><i class="fa fa-lock"></i> Password</label>
<input type="password" id="node-config-input-password" placeholder="postgres">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-config-input-ssl" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-ssl" style="width: 70%;">Use SSL</label>
</div>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('postgresdb',{
category: 'config',
color:"rgb(218, 196, 180)",
defaults: {
connectionstring : {value:""},
hostname: { value:"localhost"},
port: { value: 5432},
db: { value:"postgres"},
ssl: { value:false }
},
credentials: {
user: {type: "text"},
password: {type: "password"}
},
label: function() {
return this.name|| this.connectionstring || this.hostname+":"+this.port+"/"+this.db;
}
});
})();
</script>
<script type="text/x-red" data-template-name="PG Connection">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-postgresdb"><i class="fa fa-tag"></i> Server</label>
<input type="text" id="node-input-postgresdb">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-output" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-output" style="width: 70%;">Receive query output ?</label>
</div>
</script>
<script type="text/x-red" data-help-name="PG Connection">
<p>A PostgreSql I/O node. </p>
<p>Executes the query specified in msg.payload with optional query parameters in msg.queryParameters</p>
<p>The queryParameters in the query must be specified as $propertyname</p>
<p>See the node-postgres-named package for more info</p>
<p>When receiving data from the query, the msg.payload on the output will be a json array of the returned records</p>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('PG Connection',{
category: 'storage-output',
color:"rgb(148, 226, 252)",
defaults: {
postgresdb: { type:"postgresdb",required:true},
name: {value:""},
output: {value:false},
outputs: {value:0}
},
inputs: 1,
outputs: 0,
icon: "postgres.png",
align: "right",
label: function() {
return this.name||(this.sqlquery?this.sqlquery:"postgres");
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$( "#node-input-output" ).prop( "checked", this.output );
$("#node-input-name").focus();
},
oneditsave: function() {
var hasOutput = $( "#node-input-output" ).prop( "checked" );
this.outputs = hasOutput ? 1:0;
}
});
})();
</script>
<!--
Copyright 2015 Red Connect.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/x-red" data-template-name="postgresarray">
<div class="form-row">
<label style="vertical-align: top;"><i class="fa fa-tag"></i> Accepted Columns</label>
<div style="width:calc( 70% + 2em);display:inline-block">
<div id="postgres-array-columns">
<h4 class="muted" id="postgres-array-columns-any">Any</h4>
</div>
<div>
<input type="text" id="postgres-array-add-column-text" placeholder="Column Name" style="width:calc( 100% - 5em)"/>
<a class="editor-button fa fa-plus" id="postgres-array-add-column"></a>
</div>
</div>
</div>
<input type="hidden" id="node-config-input-columns" value="[]" />
</script>
<script type="text/javascript">
(function() {
function _removeColumn(columnName,cols,columnElement) {
return function () {
$(columnElement).remove();
var columnIndex = cols.indexOf(columnName);
if (columnIndex !== -1) {
cols.splice(columnIndex,1);
}
if (cols.length === 0) {
$('#postgres-array-columns-any').show();
}
$('#node-config-input-columns').val(JSON.stringify(cols));
}
}
function _addColumnElement(columnName,cols) {
var columnElement =
$('<div class="label label-info" style="margin : .1em .3em;" />')
.append($('<span style="margin: 0.2em; font-size: 1.3em;line-height: 1.3em;" />').text(columnName));
columnElement.append($('<a class="btn btn-danger fa fa-times" style="padding:.2em .3em;margin: -.3em .1em .2em .1em;"/>')
.click(_removeColumn(columnName,cols,columnElement)));
$('#postgres-array-columns').append(columnElement);
}
RED.nodes.registerType('postgresarray',{
category: 'config',
color:"rgb(148, 226, 252)",
defaults: {
columns: { value: "[]" }
},
columns: "[]",
label: function() {
var cols = JSON.parse(this.columns);
return cols.length ? cols.join() : '*';
},
oneditprepare: function() {
var node=this;
node._columns = JSON.parse(this.columns);
if (node._columns.length > 0) {
$('#postgres-array-columns-any').hide();
for (var i=0,l=node._columns.length;i<l;i++) {
_addColumnElement(node._columns[i],node._columns);
}
}
$("#postgres-array-add-column").click(function () {
var columnName = $('#postgres-array-add-column-text').val().toLowerCase().trim();
if (node._columns.length === 0) {
$('#postgres-array-columns-any').hide();
}
//Check if already exists
if ((columnName.length > 0) && (node._columns.indexOf(columnName) === -1)) {
$('#postgres-array-add-column-text').val('');
_addColumnElement(columnName,node._columns);
node._columns.push(columnName);
$('#node-config-input-columns').val(JSON.stringify(node._columns));
}
});
$('#node-config-input-columns').val(JSON.stringify(node._columns));
}
});
})();
</script>
<script type="text/x-red" data-template-name="PG Insert">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-table"><i class="fa fa-tag"></i> Table name</label>
<input type="text" id="node-input-table" placeholder="Table name">
</div>
<div class="form-row">
<label for="node-input-name" style="vertical-align: top;"><i class="fa fa-tag"></i> Accepted Columns</label>
<input type="text" id="node-input-columns">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-require-all" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-require-all" style="width: 70%;">All columns required ?</label>
</div>
</script>
<script type="text/x-red" data-help-name="PG Insert">
<p>A PostgreSql I/O insert node. </p>
<p>Transform the object in msg.payload to a insert query</p>
<p>You can filter which columns take from the input using the Accepted Columns field, or leave it blank to accept everything</p>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('PG Insert',{
category: 'storage-output',
color:"rgb(148, 226, 252)",
defaults: {
name: { value:"" },
table: { value:"", required : true },
columns: { type:"postgresarray" },
requireAll: { value: false }
},
inputs: 1,
outputs: 1,
icon: "arrow-in.png",
label: function() {
return this.name||("insert on "+this.table);
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$("#node-input-require-all").prop("checked", this.requireAll);
$("#node-input-name").focus();
},
oneditsave: function() {
this.requireAll = $( "#node-input-require-all" ).prop( "checked" ) + 0;
}
});
})();
</script>
<script type="text/x-red" data-template-name="PG Update">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-table"><i class="fa fa-tag"></i> Table name</label>
<input type="text" id="node-input-table" placeholder="Table name">
</div>
<div class="form-row">
<label for="node-input-columns" style="vertical-align: top;"><i class="fa fa-tag"></i> Accepted Columns</label>
<input type="text" id="node-input-columns">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-require-all" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-require-all" style="width: 70%;">All columns required ?</label>
</div>
<div class="form-row">
<label for="node-input-where" style="vertical-align: top;"><i class="fa fa-tag"></i> Where Columns</label>
<input type="text" id="node-input-where">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-require-all" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-require-all-where" style="width: 70%;">All columns required ?</label>
</div>
</script>
<script type="text/x-red" data-help-name="PG Update">
<p>A PostgreSql I/O update node. </p>
<p>Transform the object in msg.payload to a update query</p>
<p>You can filter which columns take from the input using the Accepted Columns field, or leave it blank to accept everything</p>
<p>You can optionally add an object in msg.where for make the where clausey</p>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('PG Update',{
category: 'storage-output',
color:"rgb(148, 226, 252)",
defaults: {
name: { value:"" },
table: { value:"", required : true },
columns: { type:"postgresarray" },
where: { type:"postgresarray" },
requireAll: { value: false },
requireAllWhere: { value: false }
},
inputs: 1,
outputs: 1,
icon: "arrow-in.png",
label: function() {
return this.name||("update on "+this.table);
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$("#node-input-require-all").prop("checked", this.requireAll);
$("#node-input-require-all-where").prop("checked", this.requireAllWhere);
$("#node-input-name").focus();
},
oneditsave: function() {
this.requireAll = $( "#node-input-require-all" ).prop( "checked" ) + 0;
this.requireAllWhere = $( "#node-input-require-all-where" ).prop( "checked" ) + 0;
}
});
})();
</script>
<script type="text/x-red" data-template-name="PG Select">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-table"><i class="fa fa-tag"></i> Table name</label>
<input type="text" id="node-input-table" placeholder="Table name">
</div>
<div class="form-row">
<label for="node-input-columns" style="vertical-align: top;"><i class="fa fa-tag"></i> Columns</label>
<input type="text" id="node-input-columns">
</div>
<div class="form-row">
<label for="node-input-where" style="vertical-align: top;"><i class="fa fa-tag"></i> Where Columns</label>
<input type="text" id="node-input-where">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-require-all" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-require-all" style="width: 70%;">All columns required ?</label>
<label> </label>
<input type="checkbox" id="node-input-no-where" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-no-where" style="width: 70%;">Ignore the where clause ?</label>
</div>
<div class="form-row">
<label for="node-input-group" style="vertical-align: top;"><i class="fa fa-tag"></i> Group by</label>
<input type="text" id="node-input-group">
</div>
<div class="form-row">
<label> </label>
<input type="checkbox" id="node-input-orderRawActive" placeholder="once" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-orderRawActive" style="width: 70%;">Activate OrderBy RAW ?</label>
</div>
<div class="form-row">
<label for="node-input-orderRaw" style="vertical-align: top;"><i class="fa fa-tag"></i> Order by (RAW) </label>
<input type="text" id="node-input-orderRaw">
</div>
<div class="form-row">
<label for="node-input-order" style="vertical-align: top;"><i class="fa fa-tag"></i> Order by</label>
<input type="text" id="node-input-order">
</div>
<div class="form-row">
<label for="node-input-limit"><i class="fa fa-tag"></i> Limit</label>
<input type="text" id="node-input-limit" placeholder="Limit">
</div>
<div class="form-row">
<label for="node-input-offset"><i class="fa fa-tag"></i> Offset</label>
<input type="text" id="node-input-offset" placeholder="Offset">
</div>
</script>
<script type="text/x-red" data-help-name="PG Select">
<p>A PostgreSql I/O select node. </p>
<p>Build a select query using the msg.payload as where clause</p>
<p></p>
<p>Optionally you can use msg.limit for the limit (if is setted 0 on the settings of the node)</p>
<p>and msg.offset for the offset (if is setted 0 on the settings of the node)</p>
<h5>Order Raw / Order:</h5>
<p>You can use the Order Raw Field to write e.g. a function directy into the Order Statement. See here: <a href="http://knexjs.org/#Builder-orderByRaw">OrderByRaw</a></p>
</script>
<script type="text/javascript">
(function() {
RED.nodes.registerType('PG Select',{
category: 'storage-output',
color:"rgb(148, 226, 252)",
defaults: {
name: { value:"" },
table: { value:"", required : true },
limit: { value:"0", validate:RED.validators.number() },
offset: { value:"0", validate:RED.validators.number() },
columns: { type:"postgresarray" },
where: { type:"postgresarray" },
group: { type:"postgresarray" },
order: { type:"postgresarray" },
orderRawActive: { value: false },
orderRaw: { value: ""},
requireAll: { value: false },
noWhere: { value: false }
},
inputs: 1,
outputs: 1,
icon: "arrow-in.png",
label: function() {
return this.name||("select on "+this.table);
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function() {
$("#node-input-require-all").prop("checked", this.requireAll);
$("#node-input-no-where").prop("checked", this.noWhere);
$("#node-input-name").focus();
},
oneditsave: function() {
this.requireAll = $( "#node-input-require-all" ).prop( "checked" ) + 0;
this.noWhere = $( "#node-input-no-where" ).prop( "checked" ) + 0;
}
});
})();
</script>