Skip to content

Commit bf62917

Browse files
committed
Improve docs
1 parent 7c2febb commit bf62917

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,11 @@ The copy commands are not supported.
244244
const pool = createPool({
245245
create: async () => {
246246
const client = new Client();
247-
return client.connect().then(() => {
248-
client.on('error', console.log);
249-
return client;
250-
});
251-
},
252-
destroy: async (client: Client) => {
253-
return client.end().then(() => { })
247+
await client.connect();
248+
client.on('error', console.log);
249+
return client;
254250
},
251+
destroy: async (client: Client) => client.end(),
255252
validate: (client: Client) => {
256253
return Promise.resolve(!client.closed);
257254
}
@@ -267,8 +264,20 @@ The copy commands are not supported.
267264
const result = client.query({text: ..., transform: camelcase})
268265
```
269266

270-
3. _How do I use LISTEN/NOTIFY?_ Send `LISTEN` as a regular query, then subscribe to notifications
271-
using `on(event: 'notification', callback: Callback<Notification>)`.
267+
3. _How do I use LISTEN/NOTIFY?_ Send `LISTEN` as a regular query, then subscribe to
268+
notifications, filtering out the relevant channels.
269+
270+
```typescript
271+
import { Notification } from 'ts-postgres';
272+
273+
const channel = 'test';
274+
client.on('notification', (message: Notification) => {
275+
if (message.channel === channel) {
276+
// Do stuff
277+
}
278+
});
279+
await client.query(`LISTEN ${channel}`);
280+
```
272281

273282
## Benchmarking
274283

0 commit comments

Comments
 (0)