Skip to content

Commit

Permalink
Use NoticeMessage type for pg.Client 'notice' event.
Browse files Browse the repository at this point in the history
  • Loading branch information
groner committed Feb 11, 2021
1 parent c5e3868 commit 921fd91
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion types/pg/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import events = require('events');
import stream = require('stream');
import pgTypes = require('pg-types');
import { NoticeMessage } from 'pg-protocol/dist/messages';

import { ConnectionOptions } from 'tls';

Expand Down Expand Up @@ -248,7 +249,8 @@ export class ClientBase extends events.EventEmitter {
escapeLiteral(str: string): string;

on(event: 'drain', listener: () => void): this;
on(event: 'error' | 'notice', listener: (err: Error) => void): this;
on(event: 'error', listener: (err: Error) => void): this;
on(event: 'notice', listener: (notice: NoticeMessage) => void): this;
on(event: 'notification', listener: (message: Notification) => void): this;
// tslint:disable-next-line unified-signatures
on(event: 'end', listener: () => void): this;
Expand Down
3 changes: 2 additions & 1 deletion types/pg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"dependencies": {
"pg-types": "^2.2.0"
"pg-types": "^2.2.0",
"pg-protocol": "^1.2.0"
}
}
2 changes: 2 additions & 0 deletions types/pg/pg-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { types, Client, CustomTypesConfig, QueryArrayConfig, Pool } from 'pg';
import { NoticeMessage } from 'pg-protocol/dist/messages';

// https://github.com/brianc/node-pg-types
// tslint:disable-next-line no-unnecessary-callback-wrapper
Expand All @@ -20,6 +21,7 @@ const host: string = client.host;
const password: string | undefined = client.password;
const ssl: boolean = client.ssl;

client.on('notice', (notice: NoticeMessage) => console.warn(`${notice.severity}: ${notice.message}`));
client.connect(err => {
if (err) {
console.error('Could not connect to postgres', err);
Expand Down

0 comments on commit 921fd91

Please sign in to comment.