Skip to content

Commit 63f4790

Browse files
committed
Adding EventEmitter for the Client class.
1 parent 58dc975 commit 63f4790

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

test/typescript/pg.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ import * as pgPromise from 'pg-promise';
44
import * as pgSubset from 'pg-subset';
55

66
var pgp:pgPromise.IMain = pgPromise();
7+
var db = pgp('connection');
78

89
var pg = pgp.pg;
910

1011
var client = new pg.Client({});
12+
13+
db.connect()
14+
.then(t=> {
15+
t.client.on('notification', (message)=> {
16+
var s = message.anything;
17+
});
18+
t.client.removeAllListeners();
19+
});
20+
1121
var query = new pg.Query();
1222
var connection = new pg.Connection();
1323

typescript/pg-subset.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
// pg: https://github.com/brianc/node-postgres
1010
//////////////////////////////////////////////////////////////////////////////
1111

12+
/// <reference path='../typings/index' />
13+
1214
declare module 'pg-subset' {
1315

16+
import { EventEmitter } from 'events';
17+
1418
namespace pg {
1519

1620
interface IColumn {
@@ -118,12 +122,18 @@ declare module 'pg-subset' {
118122
// not needed within pg-promise;
119123
}
120124

121-
class Client {
125+
class Client extends EventEmitter {
122126

123127
constructor(config:any);
124128

125129
query:(config:any, values:any, callback:(err:Error, result:IResult)=>void)=>Query;
126130

131+
on(event: 'drain', listener: () => void): this;
132+
on(event: 'error', listener: (err: Error) => void): this;
133+
on(event: 'notification', listener: (message: any) => void): this;
134+
on(event: 'notice', listener: (message: any) => void): this;
135+
on(event: string, listener: Function): this;
136+
127137
connectionParameters:IConnectionParameters;
128138
database:string;
129139
user:string;

typings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"typescript/pg-subset.d.ts"
99
],
1010
"globalDependencies": {
11-
"spex": "github:vitaly-t/spex"
11+
"node": "registry:env/node#4.0.0+20160622202520",
12+
"spex": "github:vitaly-t/spex#dab68c4589973c1a9da828b90d40490054c64b80"
1213
}
1314
}

0 commit comments

Comments
 (0)