@@ -244,14 +244,11 @@ The copy commands are not supported.
244
244
const pool = createPool ({
245
245
create : async () => {
246
246
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 ;
254
250
},
251
+ destroy : async (client : Client ) => client .end (),
255
252
validate : (client : Client ) => {
256
253
return Promise .resolve (! client .closed );
257
254
}
@@ -267,8 +264,20 @@ The copy commands are not supported.
267
264
const result = client .query ({text: ... , transform: camelcase })
268
265
```
269
266
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
+ ```
272
281
273
282
## Benchmarking
274
283
0 commit comments