Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "pg-listen", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"license": "MIT", | ||
@@ -47,2 +47,5 @@ "description": "PostgreSQL LISTEN & NOTIFY that finally works.", | ||
}, | ||
"files": [ | ||
"dist/**" | ||
], | ||
"ava": { | ||
@@ -49,0 +52,0 @@ "serial": true |
@@ -1,2 +0,2 @@ | ||
# pg-listen - PostgreSQL LISTEN & NOTIFY that finally works | ||
# pg-listen - Postgres LISTEN & NOTIFY that works | ||
@@ -20,3 +20,3 @@ [![Build Status](https://travis-ci.org/andywer/pg-listen.svg?branch=master)](https://travis-ci.org/andywer/pg-listen) [![NPM Version](https://img.shields.io/npm/v/pg-listen.svg)](https://www.npmjs.com/package/pg-listen) | ||
Using the `NOTIFY` and `LISTEN` features is not trivial using [`node-postgres` (`pg`)](https://www.npmjs.com/package/pg), since you cannot use connection pools and also distinct client connections also tend to time out. | ||
Using the `NOTIFY` and `LISTEN` features is not trivial using [`node-postgres` (`pg`)](https://www.npmjs.com/package/pg), since you cannot use connection pools and even distinct client connections also tend to time out. | ||
@@ -43,2 +43,3 @@ There are already a few packages out there, like `pg-pubsub`, but neither of them seems to work reliably. Errors are being swallowed, the code is hard to reason about, there is no type-safety, ... | ||
import createPostgresSubscriber from "pg-listen" | ||
import { databaseURL } from "./config" | ||
@@ -51,2 +52,8 @@ const subscriber = createPostgresSubscriber({ connectionString: databaseURL }) | ||
subscriber.events.on("error", (error) => { | ||
// Usually triggered if reconnection attempts have failed repeatedly | ||
console.error("Fatal database connection error:", error) | ||
process.exit(1) | ||
}) | ||
process.on("exit", () => { | ||
@@ -56,3 +63,3 @@ subscriber.close() | ||
export async function setUp (databaseURL) { | ||
export async function connect () { | ||
await subscriber.connect() | ||
@@ -89,3 +96,7 @@ await subscriber.listenTo("my-channel") | ||
### `instance.notifications.on(channelName: string, listener: (payload: any) => void)` | ||
The convenient way of subscribing to notifications. Don't forget to call `.listenTo(channelName)` to subscribe the Postgres client to this channel in order to receive notifications. | ||
## Debugging | ||
@@ -92,0 +103,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23085
105
7
364
1