Readonly
onEmits when a new connection has been established.
Readonly
onEmits when a connection has been lost (temporarily), and is due for automatic reconnection.
Readonly
onEmits when the connection has been lost permanently.
After this event, all LISTEN
subscribers have received the error
event,
and the class is no longer usable.
This is for monitoring / logging purposes.
Readonly
onEmits all SQL queries being executed.
This is for monitoring / logging purposes.
Returns true if the connection is currently active.
Returns true
if the connection is either active or being established.
Returns false
when the connection is lost permanently, and onEnd has been emitted.
List of channels that are currently being listened to.
Creates an observable that emits LISTEN
notifications for the specified channels.
Note that it does not trigger a connection with listening. That happens only after you subscribe to the returned observable.
List of channels to listen to.
Optional
ready: () => voidOptional callback for when connection has been established, and queries finished execution. It is re-sent when the connection changes or new subscribers appear.
An observable that emits LISTEN
notifications for the specified channels.
Sends a notification into the specified channels, with optional payload.
List of channels to notify.
Optional
payload: stringOptional payload to send with the notification.
true
if the notification was sent successfully, false
otherwise.
// "ls" is of type "PgListenConnection"
ls.listen(['channel_1', 'channel_2'], async () => {
await ls.notify(['channel_1', 'channel_2'], 'Hello World!');
})
.subscribe(msg => {
console.log(msg);
});
Output:
{
channel: 'channel_1',
length: 31,
payload: 'Hello World!',
processId: 644
}
{
channel: 'channel_2',
length: 31,
payload: 'Hello World!',
processId: 644
}
A class that represents a single connection to a PostgreSQL database and provides methods for listening to and sending notifications.