-
Notifications
You must be signed in to change notification settings - Fork 217
/
pg-subset.d.ts
280 lines (233 loc) · 7.57 KB
/
pg-subset.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
* Copyright (c) 2015-present, Vitaly Tomilov
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Removal or modification of this copyright notice is prohibited.
*/
//////////////////////////////////////////////////////////////////////////////
// Declaring only a subset of the 'pg' module that's useful within pg-promise.
//
// Calling it 'pg-subset' to avoid a conflict in case the application also
// includes the official 'pg' typings.
//
// Supported version of pg: 7.12.1 and later.
//
// pg: https://github.com/brianc/node-postgres
//////////////////////////////////////////////////////////////////////////////
import {EventEmitter} from 'events';
import {checkServerIdentity} from 'tls';
declare namespace pg {
interface IColumn {
name: string
oid: number
dataTypeID: number
// NOTE: properties below are not available within Native Bindings:
tableID: number
columnID: number
dataTypeSize: number
dataTypeModifier: number
format: string
}
interface IResult {
command: string
rowCount: number
rows: any[]
fields: IColumn[]
// properties below are not available within Native Bindings:
rowAsArray: boolean
_types: {
_types: any,
text: any,
binary: any
};
_parsers: Array<Function>;
}
// SSL configuration;
// For property types and documentation see:
// http://nodejs.org/api/tls.html#tls_tls_connect_options_callback
interface ISSLConfig {
ca?: string | Buffer | Array<string | Buffer>
pfx?: string | Buffer | Array<string | Buffer | object>
cert?: string | Buffer | Array<string | Buffer>
key?: string | Buffer | Array<Buffer | object>
passphrase?: string
rejectUnauthorized?: boolean
checkServerIdentity?: typeof checkServerIdentity
secureOptions?: number
NPNProtocols?: string[] | Buffer | Buffer[] | Uint8Array | Uint8Array[]
}
type DynamicPassword = string | (() => string) | (() => Promise<string>);
// See:
// 1) https://github.com/brianc/node-postgres/blob/master/lib/defaults.js
// 2) https://github.com/brianc/node-pg-pool
interface IConnectionParameters {
connectionString?: string
host?: string
database?: string
user?: string
password?: DynamicPassword
port?: number
ssl?: boolean | ISSLConfig
binary?: boolean
client_encoding?: string
encoding?: string
application_name?: string
fallback_application_name?: string
isDomainSocket?: boolean
max?: number
min?: number
idleTimeoutMillis?: number
parseInputDatesAsUTC?: boolean
rows?: number
statement_timeout?: boolean | number
query_timeout?: boolean | number
connect_timeout?: number
keepAliveInitialDelayMillis?: number
keepAlive?: boolean
keepalives?: number
keepalives_idle?: number
}
// Type id-s supported by PostgreSQL, copied from:
// http://github.com/brianc/node-pg-types/blob/master/lib/builtins.js
enum TypeId {
BOOL = 16,
BYTEA = 17,
CHAR = 18,
INT8 = 20,
INT2 = 21,
INT4 = 23,
REGPROC = 24,
TEXT = 25,
OID = 26,
TID = 27,
XID = 28,
CID = 29,
JSON = 114,
XML = 142,
PG_NODE_TREE = 194,
SMGR = 210,
PATH = 602,
POLYGON = 604,
CIDR = 650,
FLOAT4 = 700,
FLOAT8 = 701,
ABSTIME = 702,
RELTIME = 703,
TINTERVAL = 704,
CIRCLE = 718,
MACADDR8 = 774,
MONEY = 790,
MACADDR = 829,
INET = 869,
ACLITEM = 1033,
BPCHAR = 1042,
VARCHAR = 1043,
DATE = 1082,
TIME = 1083,
TIMESTAMP = 1114,
TIMESTAMPTZ = 1184,
INTERVAL = 1186,
TIMETZ = 1266,
BIT = 1560,
VARBIT = 1562,
NUMERIC = 1700,
REFCURSOR = 1790,
REGPROCEDURE = 2202,
REGOPER = 2203,
REGOPERATOR = 2204,
REGCLASS = 2205,
REGTYPE = 2206,
UUID = 2950,
TXID_SNAPSHOT = 2970,
PG_LSN = 3220,
PG_NDISTINCT = 3361,
PG_DEPENDENCIES = 3402,
TSVECTOR = 3614,
TSQUERY = 3615,
GTSVECTOR = 3642,
REGCONFIG = 3734,
REGDICTIONARY = 3769,
JSONB = 3802,
REGNAMESPACE = 4089,
REGROLE = 4096
}
// Interface of 'pg-types' module;
// See: https://github.com/brianc/node-pg-types
interface ITypes {
setTypeParser: (id: TypeId, format: string | ((value: string) => any)) => void
getTypeParser: (id: TypeId, format?: string) => any
arrayParser: (source: string, transform: (entry: any) => any) => any[]
builtins: typeof TypeId
}
interface IDefaults {
// connection string for overriding defaults
connectionString: string
// database host. defaults to localhost
host: string
// database user's name
user: string
// name of database to connect
database: string
// database user's password
password: DynamicPassword
// database port
port: number
// number of rows to return at a time from a prepared statement's
// portal. 0 will return all rows at once
rows: number
// binary result mode
binary: boolean
// Connection pool options - see https://github.com/brianc/node-pg-pool
// number of connections to use in connection pool
// 0 will disable connection pooling
max: number,
// max milliseconds a client can go unused before it is removed
// from the pool and destroyed
idleTimeoutMillis: number
client_encoding: string
ssl: boolean | ISSLConfig
application_name: string
fallback_application_name: string
parseInputDatesAsUTC: boolean
// max milliseconds any query using this connection will execute for before timing out in error.
// false=unlimited
statement_timeout: boolean | number
// max milliseconds to wait for query to complete (client side)
query_timeout: boolean | number
connect_timeout: number
keepalives: number
keepalives_idle: number
}
class Query {
// not used within pg-promise;
}
class Client extends EventEmitter {
constructor(cn: string | IConnectionParameters)
query: (config: any, values: any, callback: (err: Error, result: IResult) => void) => Query;
on(event: 'drain', listener: () => void): this
on(event: 'error', listener: (err: Error) => void): this
on(event: 'notification', listener: (message: any) => void): this
on(event: 'notice', listener: (message: any) => void): this
on(event: string, listener: Function): this
connectionParameters: IConnectionParameters;
database: string;
user: string;
password: DynamicPassword;
port: number;
host: string;
// properties below are not available within Native Bindings:
queryQueue: Query[];
binary: boolean;
ssl: boolean | ISSLConfig;
secretKey: number;
processID: number;
encoding: string;
readyForQuery: boolean;
activeQuery: Query;
}
const defaults: IDefaults;
const types: ITypes;
}
export = pg;