Skip to content

Commit e8e3b38

Browse files
committed
Add support for LISTEN / NOTIFY / RAISE events
New option *Keep listening for notifications* https://www.postgresql.org/docs/current/sql-listen.html
1 parent b522268 commit e8e3b38

File tree

7 files changed

+343
-134
lines changed

7 files changed

+343
-134
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ It supports *splitting* the resultset and *backpressure* (flow control), to allo
77

88
It supports *parameterized queries* and *multiple queries*.
99

10+
It supports [`LISTEN`](https://www.postgresql.org/docs/current/sql-listen.html) / [`NOTIFY`](https://www.postgresql.org/docs/current/sql-notify.html) / [`RAISE`](https://www.postgresql.org/docs/current/plpgsql-errors-and-messages.html) events.
11+
1012
## Outputs
1113

1214
The response (rows) is provided in `msg.payload` as an array.
@@ -19,6 +21,22 @@ See the [underlying documentation](https://node-postgres.com/apis/result) for de
1921

2022
In the case of multiple queries, then `msg.pgsql` is an array.
2123

24+
## Events
25+
26+
If you tick the *Keep listening for notifications* option along with a [`LISTEN`](https://www.postgresql.org/docs/current/sql-listen.html) request (see below),
27+
you will receive a message for each [`NOTIFY`](https://www.postgresql.org/docs/current/sql-notify.html) event,
28+
where `msg.channel` is the name of the channel, `msg.payload` is content of the notification, and `msg.processId` indicates the process ID.
29+
30+
```sql
31+
LISTEN my_topic;
32+
```
33+
34+
This can be especially useful when combined with a [`TRIGGER`](https://www.postgresql.org/docs/15/sql-createtrigger.html) to be informed of database changes such as new insertions.
35+
36+
See the [underlying documentation](https://node-postgres.com/apis/client#notification) for details.
37+
38+
Likewise, you may get notice messages producted by [`RAISE`](https://www.postgresql.org/docs/current/plpgsql-errors-and-messages.html) as a `msg.notice` message.
39+
2240
## Inputs
2341

2442
### SQL query template

locales/en-US/postgresql.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ <h3>Outputs</h3>
1616
</p>
1717
<p>In the case of multiple queries, then <code>msg.pgsql</code> is an array.</p>
1818

19+
<h3>Events</h3>
20+
<p>
21+
If you tick the <em>Keep listening for notifications</em> option along with a <a href="https://www.postgresql.org/docs/current/sql-listen.html"><code>LISTEN</code></a> request (see below),
22+
you will receive a message for each <a href="https://www.postgresql.org/docs/current/sql-notify.html"><code>NOTIFY</code> event,
23+
where <code>msg.channel</code> is the name of the channel, <code>msg.payload</code> is content of the notification, and <code>msg.processId</code> indicates the process ID.
24+
</p>
25+
26+
<pre>
27+
LISTEN my_topic;
28+
</pre>
29+
30+
This can be especially useful when combined with a <a href="https://www.postgresql.org/docs/15/sql-createtrigger.html"><code>TRIGGER</code></a> to be informed of database changes such as new insertions.
31+
32+
See the <a href="https://node-postgres.com/apis/client#notification">underlying documentation</a> for details.
33+
34+
Likewise, you may get notice messages producted by <a href="https://www.postgresql.org/docs/current/plpgsql-errors-and-messages.html"><code>RAISE</code></a> as a <code>msg.notice</code> message.
35+
1936
<h3>Inputs</h3>
2037
<h4>SQL query template</h4>
2138
<p>This node uses the <a href="https://github.com/janl/mustache.js">Mustache template system</a> to generate queries based on the message:</p>

locales/en-US/postgresql.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"server": "Server",
1616
"query": "Query",
1717
"split": "Split results in multiple messages",
18+
"listen": "Keep listening for notifications",
1819
"rowsPerMsg": "Number of rows per message"
1920
},
2021
"placeholder": {

0 commit comments

Comments
 (0)