@depup/pg-promise 12.6.2-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/lib/assert.js +10 -0
  4. package/lib/connect.js +178 -0
  5. package/lib/context.js +93 -0
  6. package/lib/database-pool.js +115 -0
  7. package/lib/database.js +1643 -0
  8. package/lib/errors/README.md +13 -0
  9. package/lib/errors/index.js +51 -0
  10. package/lib/errors/parameterized-query-error.js +71 -0
  11. package/lib/errors/prepared-statement-error.js +71 -0
  12. package/lib/errors/query-file-error.js +75 -0
  13. package/lib/errors/query-result-error.js +157 -0
  14. package/lib/events.js +543 -0
  15. package/lib/formatting.js +932 -0
  16. package/lib/helpers/README.md +10 -0
  17. package/lib/helpers/column-set.js +614 -0
  18. package/lib/helpers/column.js +406 -0
  19. package/lib/helpers/index.js +75 -0
  20. package/lib/helpers/methods/concat.js +103 -0
  21. package/lib/helpers/methods/index.js +13 -0
  22. package/lib/helpers/methods/insert.js +151 -0
  23. package/lib/helpers/methods/sets.js +81 -0
  24. package/lib/helpers/methods/update.js +248 -0
  25. package/lib/helpers/methods/values.js +116 -0
  26. package/lib/helpers/table-name.js +175 -0
  27. package/lib/index.js +29 -0
  28. package/lib/inner-state.js +39 -0
  29. package/lib/main.js +394 -0
  30. package/lib/patterns.js +43 -0
  31. package/lib/query-file.js +379 -0
  32. package/lib/query-result.js +39 -0
  33. package/lib/query.js +273 -0
  34. package/lib/special-query.js +30 -0
  35. package/lib/stream.js +125 -0
  36. package/lib/task.js +404 -0
  37. package/lib/text.js +40 -0
  38. package/lib/tx-mode.js +194 -0
  39. package/lib/types/index.js +18 -0
  40. package/lib/types/parameterized-query.js +247 -0
  41. package/lib/types/prepared-statement.js +298 -0
  42. package/lib/types/server-formatting.js +92 -0
  43. package/lib/utils/README.md +13 -0
  44. package/lib/utils/color.js +68 -0
  45. package/lib/utils/index.js +199 -0
  46. package/lib/utils/public.js +312 -0
  47. package/package.json +77 -0
  48. package/typescript/README.md +63 -0
  49. package/typescript/pg-promise.d.ts +728 -0
  50. package/typescript/pg-subset.d.ts +359 -0
  51. package/typescript/tslint.json +21 -0
@@ -0,0 +1,359 @@
1
+ /*
2
+ * Copyright (c) 2015-present, Vitaly Tomilov
3
+ *
4
+ * See the LICENSE file at the top-level directory of this distribution
5
+ * for licensing information.
6
+ *
7
+ * Removal or modification of this copyright notice is prohibited.
8
+ */
9
+
10
+ //////////////////////////////////////////////////////////////////////////////
11
+ // Declaring only a subset of the 'pg' module that's useful within pg-promise.
12
+ //
13
+ // Calling it 'pg-subset' to avoid a conflict in case the application also
14
+ // includes the official 'pg' typings.
15
+ //
16
+ // Supported version of pg: 8.9.0 and later.
17
+ //
18
+ // pg: https://github.com/brianc/node-postgres
19
+ //////////////////////////////////////////////////////////////////////////////
20
+
21
+ import {EventEmitter} from 'events';
22
+ import {checkServerIdentity} from 'tls';
23
+
24
+ declare namespace pg {
25
+
26
+ import Socket = NodeJS.Socket;
27
+
28
+ interface IColumn {
29
+ name: string
30
+ oid: number
31
+ dataTypeID: number
32
+
33
+ // NOTE: The properties below are not available within Native Bindings:
34
+
35
+ tableID: number
36
+ columnID: number
37
+ dataTypeSize: number
38
+ dataTypeModifier: number
39
+ format: string
40
+ }
41
+
42
+ interface IResult<T = unknown> extends Iterable<T> {
43
+ command: string
44
+ rowCount: number
45
+ rows: T[]
46
+ fields: IColumn[]
47
+
48
+ // properties below are not available within Native Bindings:
49
+ rowAsArray: boolean
50
+
51
+ _types: {
52
+ _types: any,
53
+ text: any,
54
+ binary: any
55
+ };
56
+ _parsers: Array<Function>;
57
+ }
58
+
59
+ // SSL configuration;
60
+ // For property types and documentation see:
61
+ // http://nodejs.org/api/tls.html#tls_tls_connect_options_callback
62
+ interface ISSLConfig {
63
+ ca?: string | Buffer | Array<string | Buffer>
64
+ pfx?: string | Buffer | Array<string | Buffer | object>
65
+ cert?: string | Buffer | Array<string | Buffer>
66
+ key?: string | Buffer | Array<Buffer | object>
67
+ passphrase?: string
68
+ rejectUnauthorized?: boolean
69
+ checkServerIdentity?: typeof checkServerIdentity
70
+ secureOptions?: number
71
+ NPNProtocols?: string[] | Buffer | Buffer[] | Uint8Array | Uint8Array[]
72
+ }
73
+
74
+ type DynamicPassword = string | (() => string) | (() => Promise<string>);
75
+
76
+ // See:
77
+ // 1) https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/defaults.js
78
+ // 2) https://github.com/brianc/node-pg-pool
79
+ interface IConnectionParameters<C extends IClient = IClient> {
80
+ connectionString?: string
81
+ host?: string
82
+ database?: string
83
+ user?: string
84
+ password?: DynamicPassword
85
+ port?: number
86
+ ssl?: boolean | ISSLConfig
87
+ binary?: boolean
88
+ client_encoding?: string
89
+ encoding?: string
90
+ application_name?: string
91
+ fallback_application_name?: string
92
+ isDomainSocket?: boolean
93
+ max?: number
94
+ maxUses?: number
95
+ idleTimeoutMillis?: number
96
+ parseInputDatesAsUTC?: boolean
97
+ rows?: number
98
+
99
+ // Max milliseconds any query using this connection will execute for before timing out in error.
100
+ // false = unlimited
101
+ statement_timeout?: boolean | number
102
+
103
+ // Abort any statement that waits longer than the specified duration in milliseconds
104
+ // while attempting to acquire a lock; false = unlimited
105
+ lock_timeout?: boolean | number
106
+
107
+ // Terminate any session with an open transaction that has been idle for longer than
108
+ // the specified duration in milliseconds; false = unlimited
109
+ idle_in_transaction_session_timeout?: boolean | number
110
+
111
+ query_timeout?: boolean | number
112
+ connectionTimeoutMillis?: number
113
+ keepAliveInitialDelayMillis?: number
114
+ keepAlive?: boolean
115
+ keepalives?: number
116
+ keepalives_idle?: number
117
+ stream?: Socket | ((cn: IConnectionParameters) => Socket)
118
+ Client?: new(config: string | IConnectionParameters) => C
119
+ Promise?: any
120
+ types?: ITypeOverrides
121
+ allowExitOnIdle?: boolean
122
+ maxLifetimeSeconds?: number
123
+ enableChannelBinding?:boolean
124
+ }
125
+
126
+ // Type id-s supported by PostgreSQL, copied from:
127
+ // http://github.com/brianc/node-pg-types/blob/master/lib/builtins.js
128
+ enum TypeId {
129
+ BOOL = 16,
130
+ BYTEA = 17,
131
+ CHAR = 18,
132
+ INT8 = 20,
133
+ INT2 = 21,
134
+ INT4 = 23,
135
+ REGPROC = 24,
136
+ TEXT = 25,
137
+ OID = 26,
138
+ TID = 27,
139
+ XID = 28,
140
+ CID = 29,
141
+ JSON = 114,
142
+ XML = 142,
143
+ PG_NODE_TREE = 194,
144
+ SMGR = 210,
145
+ PATH = 602,
146
+ POLYGON = 604,
147
+ CIDR = 650,
148
+ FLOAT4 = 700,
149
+ FLOAT8 = 701,
150
+ ABSTIME = 702,
151
+ RELTIME = 703,
152
+ TINTERVAL = 704,
153
+ CIRCLE = 718,
154
+ MACADDR8 = 774,
155
+ MONEY = 790,
156
+ MACADDR = 829,
157
+ INET = 869,
158
+ ACLITEM = 1033,
159
+ BPCHAR = 1042,
160
+ VARCHAR = 1043,
161
+ DATE = 1082,
162
+ TIME = 1083,
163
+ TIMESTAMP = 1114,
164
+ TIMESTAMPTZ = 1184,
165
+ INTERVAL = 1186,
166
+ TIMETZ = 1266,
167
+ BIT = 1560,
168
+ VARBIT = 1562,
169
+ NUMERIC = 1700,
170
+ REFCURSOR = 1790,
171
+ REGPROCEDURE = 2202,
172
+ REGOPER = 2203,
173
+ REGOPERATOR = 2204,
174
+ REGCLASS = 2205,
175
+ REGTYPE = 2206,
176
+ UUID = 2950,
177
+ TXID_SNAPSHOT = 2970,
178
+ PG_LSN = 3220,
179
+ PG_NDISTINCT = 3361,
180
+ PG_DEPENDENCIES = 3402,
181
+ TSVECTOR = 3614,
182
+ TSQUERY = 3615,
183
+ GTSVECTOR = 3642,
184
+ REGCONFIG = 3734,
185
+ REGDICTIONARY = 3769,
186
+ JSONB = 3802,
187
+ REGNAMESPACE = 4089,
188
+ REGROLE = 4096
189
+ }
190
+
191
+ type ParserFormat = 'text' | 'binary';
192
+
193
+ // Interface for TypeOverrides;
194
+ // See: https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/type-overrides.js
195
+ interface ITypeOverrides {
196
+ setTypeParser(id: TypeId, parseFn: string | ((value: string) => any)): void
197
+
198
+ setTypeParser(id: TypeId, format: ParserFormat, parseFn: string | ((value: string) => any)): void
199
+
200
+ getTypeParser(id: TypeId, format?: ParserFormat): any
201
+ }
202
+
203
+ // Interface of 'pg-types' module;
204
+ // See: https://github.com/brianc/node-pg-types
205
+ interface ITypes extends ITypeOverrides {
206
+ arrayParser(source: string, transform: (entry: any) => any): any[]
207
+
208
+ builtins: typeof TypeId
209
+ }
210
+
211
+ interface IDefaults {
212
+
213
+ // connection string for overriding defaults
214
+ connectionString: string
215
+
216
+ // database host. defaults to localhost
217
+ host: string
218
+
219
+ // database user's name
220
+ user: string
221
+
222
+ // name of database to connect
223
+ database: string
224
+
225
+ // database user's password
226
+ password: DynamicPassword
227
+
228
+ // database port
229
+ port: number
230
+
231
+ // number of rows to return at a time from a prepared statement's
232
+ // portal. 0 will return all rows at once
233
+ rows: number
234
+
235
+ // binary result mode
236
+ binary: boolean
237
+
238
+ // Connection pool options - see https://github.com/brianc/node-pg-pool
239
+
240
+ // number of connections to use in connection pool
241
+ // 0 will disable connection pooling
242
+ max: number
243
+
244
+ // max milliseconds a client can go unused before it is removed from the pool and destroyed;
245
+ //
246
+ // Made unavailable in v10.5.0, due to the following:
247
+ // - https://github.com/brianc/node-postgres/issues/2139
248
+ // - https://github.com/vitaly-t/pg-promise/issues/703
249
+ //
250
+ // idleTimeoutMillis: number
251
+
252
+ client_encoding: string
253
+
254
+ ssl: boolean | ISSLConfig
255
+
256
+ application_name: string
257
+
258
+ fallback_application_name: string
259
+
260
+ parseInputDatesAsUTC: boolean
261
+
262
+ // Max milliseconds any query using this connection will execute for before timing out in error.
263
+ // false = unlimited
264
+ statement_timeout: boolean | number
265
+
266
+ // Abort any statement that waits longer than the specified duration in milliseconds
267
+ // while attempting to acquire a lock; false = unlimited
268
+ lock_timeout: boolean | number
269
+
270
+ // Terminate any session with an open transaction that has been idle for longer than
271
+ // the specified duration in milliseconds; false = unlimited
272
+ idle_in_transaction_session_timeout: boolean | number
273
+
274
+ // max milliseconds to wait for query to complete (client side)
275
+ query_timeout: boolean | number
276
+
277
+ keepalives: number
278
+
279
+ keepalives_idle: number
280
+ }
281
+
282
+ // interface IPool, as per the following implementation:
283
+ // https://github.com/brianc/node-postgres/blob/master/packages/pg-pool/index.js#L61
284
+ // NOTE: We declare only what can be used from pg-promise
285
+ interface IPool extends EventEmitter {
286
+
287
+ connect(): Promise<IClient>;
288
+
289
+ end(): Promise<undefined>;
290
+
291
+ end(cb: (err: Error) => any): any;
292
+
293
+ log: (msg: string, err?: any) => void;
294
+
295
+ readonly options: { [name: string]: any }; // connection options
296
+
297
+ readonly ended: boolean;
298
+ readonly ending: boolean;
299
+
300
+ readonly waitingCount: number;
301
+ readonly idleCount: number;
302
+ readonly totalCount: number;
303
+ readonly expiredCount: number;
304
+ }
305
+
306
+ interface IQuery {
307
+ // this type is not used within pg-promise;
308
+ }
309
+
310
+ interface IConnection extends EventEmitter {
311
+ /*
312
+ While there are many other properties exist within the connection,
313
+ the only one that may be remotely useful is the stream, to be able
314
+ to listen to its events, from within a custom Client class.
315
+ */
316
+ stream: Socket
317
+ }
318
+
319
+ interface IClient extends EventEmitter {
320
+
321
+ query<T>(config: any, values: any[], callback: (err: Error, result: IResult<T>) => void): void
322
+
323
+ query<T>(config: any, callback: (err: Error, result: IResult<T>) => void): void
324
+
325
+ query<T>(config: any, values: any[]): Promise<IResult<T>>
326
+
327
+ query<T>(config: any): Promise<IResult<T>>
328
+
329
+ release(): void
330
+
331
+ connectionParameters: IConnectionParameters
332
+ database: string
333
+ user: string
334
+ password: DynamicPassword
335
+ port: number
336
+ host: string
337
+
338
+ //////////////////////////////////////////////////////////////
339
+ // Properties below are not available within Native Bindings:
340
+
341
+ readonly serverVersion: string // PostgreSQL Server to which the client is connected
342
+
343
+ connection: IConnection
344
+ queryQueue: IQuery[]
345
+ binary: boolean
346
+ ssl: boolean | ISSLConfig
347
+ secretKey: number
348
+ processID: number
349
+ encoding: string
350
+ readyForQuery: boolean
351
+ activeQuery: IQuery
352
+ }
353
+
354
+ const defaults: IDefaults;
355
+ const types: ITypes;
356
+ const Client: new(config: string | IConnectionParameters) => IClient;
357
+ }
358
+
359
+ export = pg;
@@ -0,0 +1,21 @@
1
+ {
2
+ "rules": {
3
+ "trailing-comma": [
4
+ true,
5
+ {
6
+ "multiline": "never",
7
+ "singleline": "never"
8
+ }
9
+ ],
10
+ "quotemark": [
11
+ true,
12
+ "single"
13
+ ],
14
+ "class-name": true,
15
+ "interface-name": [
16
+ true,
17
+ "always-prefix"
18
+ ],
19
+ "no-consecutive-blank-lines": true
20
+ }
21
+ }