forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg.d.ts
92 lines (74 loc) · 3.13 KB
/
pg.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Type definitions for pg
// Project: https://github.com/brianc/node-postgres
// Definitions by: Phips Peter <http://pspeter3.com>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "pg" {
import events = require("events");
import stream = require("stream");
export function connect(connection: string, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
export function connect(config: ClientConfig, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
export function end(): void;
export interface ConnectionConfig {
user?: string;
database?: string;
password?: string;
port?: number;
host?: string;
}
export interface Defaults extends ConnectionConfig {
poolSize?: number;
poolIdleTimeout?: number;
reapIntervalMillis?: number;
binary?: boolean;
parseInt8?: boolean;
}
export interface ClientConfig extends ConnectionConfig {
ssl?: boolean;
}
export interface QueryConfig {
name?: string;
text: string;
values?: any[];
}
export interface QueryResult {
command: string;
rowCount: number;
oid: number;
rows: any[];
}
export interface ResultBuilder extends QueryResult {
addRow(row: any): void;
}
export class Client extends events.EventEmitter {
constructor(connection: string);
constructor(config: ClientConfig);
connect(callback?: (err:Error) => void): void;
end(): void;
query(queryText: string, callback?: (err: Error, result: QueryResult) => void): Query;
query(config: QueryConfig, callback?: (err: Error, result: QueryResult) => void): Query;
query(queryText: string, values: any[], callback?: (err: Error, result: QueryResult) => void): Query;
copyFrom(queryText: string): stream.Writable;
copyTo(queryText: string): stream.Readable;
pauseDrain(): void;
resumeDrain(): void;
public on(event: "drain", listener: () => void): this;
public on(event: "error", listener: (err: Error) => void): this;
public on(event: "notification", listener: (message: any) => void): this;
public on(event: "notice", listener: (message: any) => void): this;
public on(event: string, listener: Function): this;
}
export class Query extends events.EventEmitter {
public on(event: "row", listener: (row: any, result?: ResultBuilder) => void): this;
public on(event: "error", listener: (err: Error) => void): this;
public on(event: "end", listener: (result: ResultBuilder) => void): this;
public on(event: string, listener: Function): this;
}
export class Events extends events.EventEmitter {
public on(event: "error", listener: (err: Error, client: Client) => void): this;
public on(event: string, listener: Function): this;
}
namespace types {
function setTypeParser<T>(typeId: number, parser: (value: string) => T): void;
}
}