pg-rx-listen
v0.2.0
Published
RxJs wrapper for PostgreSQL LISTEN/NOTIFY
Maintainers
Readme
pg-rx-listen
RxJs solution for handling LISTEN / NOTIFY, supporting any library that exposes Pool from node-postgres.
Main Features:
- Automatically restores lost connections, with the help of retry-async.
- Auto-connects on the first subscription and disconnects on the last one.
Installation
$ npm i pg-rx-listenThe library uses pg / node-postgres (>=v8.7.0) as a peer-dependency, which you need to include in your project, either directly (if you are using pg) or indirectly (through any other library).
Usage
- With node-postgres module:
import {PgListenConnection} from 'pg-rx-listen';
import {Pool} from 'pg';
const pool = new Pool(/* db connection details */);
const ls = new PgListenConnection({pool});
ls.listen(['channel_1', 'channel_2'])
.subscribe(msg => {
console.log(msg.payload);
});- With pg-promise module:
import {PgListenConnection} from 'pg-rx-listen';
import pgPromise from 'pg-promise';
const pgp = pgPromise(/* init options */);
const db = pgp(/* db connection details */);
const ls = new PgListenConnection({pool: db.$pool as any});
ls.listen(['channel_1', 'channel_2'])
.subscribe(msg => {
console.log(msg.payload);
});And so on, you can use it with any other library that exposes the Pool instance.
For further details, see the Library API.
