diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index e2ddeb9..c0c2341 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -16,7 +16,7 @@ jobs: node-version: [18.x, 22.x] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 73040d1..b899edb 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -11,7 +11,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: 18 @@ -22,7 +22,7 @@ jobs: needs: build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-node@v3 with: node-version: 18 @@ -39,7 +39,7 @@ jobs: # contents: read # packages: write # steps: -# - uses: actions/checkout@v3 +# - uses: actions/checkout@v4 # - uses: actions/setup-node@v3 # with: # node-version: 18 diff --git a/README.md b/README.md index c97a7b3..8818bcd 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ It supports *splitting* the resultset and *backpressure* (flow control), to allo It supports *parameterized queries* and *multiple queries*. +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. + ## Outputs 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 In the case of multiple queries, then `msg.pgsql` is an array. +## Events + +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), +you will receive a message for each [`NOTIFY`](https://www.postgresql.org/docs/current/sql-notify.html) event, +where `msg.channel` is the name of the channel, `msg.payload` is content of the notification, and `msg.processId` indicates the process ID. + +```sql +LISTEN my_topic; +``` + +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. + +See the [underlying documentation](https://node-postgres.com/apis/client#notification) for details. + +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. + ## Inputs ### SQL query template diff --git a/locales/en-US/postgresql.html b/locales/en-US/postgresql.html index e5534d3..6c6f4c9 100644 --- a/locales/en-US/postgresql.html +++ b/locales/en-US/postgresql.html @@ -16,6 +16,23 @@

Outputs

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

+

Events

+

+ If you tick the Keep listening for notifications option along with a LISTEN request (see below), + you will receive a message for each NOTIFY event, + where msg.channel is the name of the channel, msg.payload is content of the notification, and msg.processId indicates the process ID. +

+ +
+LISTEN my_topic;
+
+ +This can be especially useful when combined with a
TRIGGER to be informed of database changes such as new insertions. + +See the underlying documentation for details. + +Likewise, you may get notice messages producted by RAISE as a msg.notice message. +

Inputs

SQL query template

This node uses the Mustache template system to generate queries based on the message:

diff --git a/locales/en-US/postgresql.json b/locales/en-US/postgresql.json index 5b197d2..44d6096 100644 --- a/locales/en-US/postgresql.json +++ b/locales/en-US/postgresql.json @@ -15,6 +15,7 @@ "server": "Server", "query": "Query", "split": "Split results in multiple messages", + "listen": "Keep listening for notifications", "rowsPerMsg": "Number of rows per message" }, "placeholder": { diff --git a/postgresql.html b/postgresql.html index 39ce99e..660b156 100644 --- a/postgresql.html +++ b/postgresql.html @@ -24,7 +24,7 @@ - +
- +
- +
- +
@@ -279,6 +279,12 @@ +
+ + +