1.0.5 • Published 5 months ago
pg-notify v1.0.5
Postgres PubSub client using NOTIFY/LISTEN
Features
- Auto reconnect
- Payload size validation
- Channel and payload sanitization
Install
npm install pg-notify
yarn add pg-notify
pnpm add pg-notify
Usage
PGPubSub accepts the same config as pg.
import PGPubSub from 'pg-notify'
//const PGPubSub = require('pg-notify')
;(async () => {
const pubsub = new PGPubSub({
connectionString: 'postgres://postgres:postgres@localhost:5432/db'
})
await pubsub.connect()
await pubsub.on('test', (payload) => {
console.log('payload: ', payload)
})
await pubsub.emit('test', 'this is the payload')
await pubsub.emit('test', { foo: 'bar' })
await pubsub.close()
})()
API
new PubSub(options)
options
(object
) Configuration options for pg-notify pubsub instance. Accepts same options as pg with few custom ones described below.- reconnectMaxRetries (
number
) Maximum number of reconnect attempts after losing connection. Pass0
to disable reconnecting. Default:10
. - maxPayloadSize (
number
) Maximum payload size, exceeding given size will throw an error. Default:7999
(In the default configuration it must be shorter than 8000 bytes.).
- reconnectMaxRetries (
emit(channel, payload)
channel
(string
)payload
(string
orobject
)
on(channel, listener)
channel
(string
)listener
(function
accepting single argumentpayload
)
removeListener(listener)
listener
(function
accepting single argumentpayload
)
close()
connect()
Contributing
Contributions, issues and feature requests are welcome!
License
Copyright © 2020 Aldis Ameriks. This project is MIT licensed.
1.0.5
5 months ago
1.0.4
5 months ago
1.0.3
7 months ago
1.0.2
11 months ago
1.0.1
1 year ago
1.0.0
1 year ago
0.0.21
1 year ago
0.0.20
2 years ago
0.0.19
2 years ago
0.0.17
3 years ago
0.0.18
3 years ago
0.0.16
3 years ago
0.0.15
4 years ago
0.0.14
4 years ago
0.0.12
4 years ago
0.0.11
4 years ago
0.0.10
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.5
4 years ago
0.0.6
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago