You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-20Lines changed: 28 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,21 @@ It supports *splitting* the resultset and *backpressure* (flow control), to allo
6
6
7
7
It supports *parameterized queries*.
8
8
9
-
`msg.payload` will contain the result object of the query: (see also the documentation of the [underlying node-postgres library](https://node-postgres.com/api/result))
9
+
## Outputs
10
10
11
-
*`command`: The SQL command that was executed (e.g. `SELECT`, `UPDATE`, etc.)
12
-
*`rowCount`: The number of rows affected by the SQL statement
13
-
*`oid`: The [oid](https://www.postgresql.org/docs/current/datatype-oid.html) returned
14
-
*`rows`: An array of rows
11
+
The response (rows) is provided in `msg.payload` as an array.
15
12
16
-
There is a template engine allowing parameterized queries:
13
+
An exception is if the *Split results* option is enabled and the *Number of rows per message* set to **1**, then `msg.payload` is not an array but the single-row response.
14
+
15
+
Additional information is provided as `msg.pgsql.rowCount` and `msg.pgsql.command`. See the [underlying documentation](https://node-postgres.com/api/result) for details.
16
+
17
+
In the case of multiple queries, then `msg.pgsql` is an array.
18
+
19
+
## Inputs
20
+
21
+
### SQL query template
22
+
23
+
This node uses the [Mustache template system](https://github.com/janl/mustache.js) to generate queries based on the message:
17
24
18
25
```sql
19
26
-- INTEGER id column
@@ -23,7 +30,7 @@ SELECT * FROM table WHERE id = {{{ msg.id }}};
23
30
SELECT*FROM table WHERE id ='{{{ msg.id }}}';
24
31
```
25
32
26
-
## Parameterized query
33
+
###Parameterized query
27
34
28
35
Parameters for parameterized queries can be passed as a parameter array `params` of the `msg` object:
29
36
@@ -34,7 +41,7 @@ msg.params = [ msg.id ];
34
41
35
42
```sql
36
43
-- In this node, use a parameterized query
37
-
SELECT*FROM table where name= $1;
44
+
SELECT*FROM table WHERE id= $1;
38
45
```
39
46
40
47
## Installation
@@ -44,11 +51,11 @@ SELECT * FROM table where name = $1;
44
51
You can install [**node-red-contrib-postgresql**](https://flows.nodered.org/node/node-red-contrib-postgresql) directly using the editor:
45
52
Select *Manage Palette* from the menu (top right), and then select the *Install* tab in the palette.
46
53
47
-
### Installing npm packaged nodes
54
+
### Using npm
48
55
49
-
You can also install the [npm-packaged node](https://www.npmjs.com/package/node-red-contrib-postgresql):
56
+
You can alternatively install the [npm-packaged node](https://www.npmjs.com/package/node-red-contrib-postgresql):
50
57
51
-
* Locally within your user data directory (by default, ```$HOME/.node-red```):
58
+
* Locally within your user data directory (by default, `$HOME/.node-red`):
52
59
53
60
```sh
54
61
cd$HOME/.node-red
@@ -74,19 +81,20 @@ So when the *Split results* option is enabled, this node will only output one me
74
81
To make this behaviour potentially automatic (avoiding manual wires), this node declares its ability by exposing a truthy `node.tickConsumer` for downstream nodes to detect this feature, and a truthy `node.tickProvider` for upstream nodes.
75
82
Likewise, this node detects upstream nodes using the same back-pressure convention, and automatically sends ticks.
76
83
77
-
## Sequences
84
+
## Sequences for split results
78
85
79
-
When the *Split results* option is enabled, the messages contain some information following the conventions for [*messages sequences*](https://nodered.org/docs/user-guide/messages#message-sequences).
86
+
When the *Split results* option is enabled (streaming), the messages contain some information following the conventions for [*messages sequences*](https://nodered.org/docs/user-guide/messages#message-sequences).
80
87
81
88
```js
82
89
{
83
-
payload:'...',
84
-
parts: {
85
-
id:0.1234, // sequence ID from upstream or randomly generated (changes for every sequence)
86
-
index:5, // incremented for each message of the same sequence
87
-
count:6, // total number of message; only available in the last message of a sequence
88
-
},
89
-
complete:true, // True only for the last message of a sequence
90
+
payload:'...',
91
+
parts: {
92
+
id:0.1234, // sequence ID, randomly generated (changes for every sequence)
93
+
index:5, // incremented for each message of the same sequence
94
+
count:6, // total number of message; only available in the last message of a sequence
95
+
parts: {}, // optional upstream parts information
96
+
},
97
+
complete:true, // True only for the last message of a sequence
<p><ahref="https://github.com/alexandrainst/node-red-contrib-postgresql">node-red-contrib-postgresql</a> is a Node-RED node to query a <ahref="https://www.postgresql.org/">PostgreSQL</a> 🐘 database.</p>
<p>Additional information is provided as <code>msg.pgsql.rowCount</code> and <code>msg.pgsql.command</code>. See the <ahref="https://node-postgres.com/api/result">underlying documentation</a> for details.</p>
When the <em>Split results</em> option is enabled, the messages contain some information following the conventions for <ahref="https://nodered.org/docs/user-guide/messages#message-sequences"><em>messages sequences</em></a>.
0 commit comments