@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,728 @@
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
+ import * as pg from './pg-subset';
11
+ import * as pgMinify from 'pg-minify';
12
+ import * as spexLib from 'spex';
13
+
14
+ // internal namespace for "txMode" property:
15
+ declare namespace _txMode {
16
+ // Transaction Isolation Level;
17
+ // API: https://vitaly-t.github.io/pg-promise/txMode.html#.isolationLevel
18
+ enum isolationLevel {
19
+ none = 0,
20
+ serializable = 1,
21
+ repeatableRead = 2,
22
+ readCommitted = 3
23
+ }
24
+
25
+ // TransactionMode class;
26
+ // API: https://vitaly-t.github.io/pg-promise/txMode.TransactionMode.html
27
+ class TransactionMode {
28
+ constructor(options?: { tiLevel?: isolationLevel, readOnly?: boolean, deferrable?: boolean })
29
+
30
+ begin(cap?: boolean): string
31
+ }
32
+ }
33
+
34
+ // Main protocol of the library;
35
+ // API: https://vitaly-t.github.io/pg-promise/module-pg-promise.html
36
+ declare namespace pgPromise {
37
+
38
+ interface ISpex {
39
+ batch: typeof spexLib.batch
40
+ page: typeof spexLib.page
41
+ sequence: typeof spexLib.sequence
42
+ errors: {
43
+ BatchError: spexLib.errors.BatchError,
44
+ PageError: spexLib.errors.PageError,
45
+ SequenceError: spexLib.errors.SequenceError
46
+ }
47
+ }
48
+
49
+ interface IQueryFileOptions {
50
+ debug?: boolean
51
+ minify?: boolean | 'after'
52
+ compress?: boolean
53
+ params?: any
54
+ noWarnings?: boolean
55
+ }
56
+
57
+ interface IFormattingOptions {
58
+ capSQL?: boolean
59
+ partial?: boolean
60
+ def?: any
61
+ }
62
+
63
+ interface ILostContext<C extends pg.IClient = pg.IClient> {
64
+ cn: string
65
+ dc: any
66
+ start: Date
67
+ client: C
68
+ }
69
+
70
+ interface IConnectionOptions<C extends pg.IClient = pg.IClient> {
71
+ direct?: boolean
72
+
73
+ onLost?(err: any, e: ILostContext<C>): void
74
+ }
75
+
76
+ interface IPreparedStatement {
77
+ name?: string
78
+ text?: string | QueryFile
79
+ values?: any[]
80
+ binary?: boolean
81
+ rowMode?: 'array' | null | void
82
+ rows?: number
83
+ types?: pg.ITypes
84
+ }
85
+
86
+ interface IParameterizedQuery {
87
+ text?: string | QueryFile
88
+ values?: any[]
89
+ binary?: boolean
90
+ rowMode?: void | 'array'
91
+ types?: pg.ITypes;
92
+ }
93
+
94
+ interface IPreparedParsed {
95
+ name: string
96
+ text: string
97
+ values: any[]
98
+ binary: boolean
99
+ rowMode: void | 'array'
100
+ rows: number
101
+ }
102
+
103
+ interface IParameterizedParsed {
104
+ text: string
105
+ values: any[]
106
+ binary: boolean
107
+ rowMode: void | 'array'
108
+ }
109
+
110
+ interface IColumnDescriptor<T> {
111
+ source: T
112
+ name: string
113
+ value: any
114
+ exists: boolean
115
+ }
116
+
117
+ interface IColumnConfig<T> {
118
+ name: string
119
+ prop?: string
120
+ mod?: FormattingFilter
121
+ cast?: string
122
+ cnd?: boolean
123
+ def?: any
124
+
125
+ init?(col: IColumnDescriptor<T>): any
126
+
127
+ skip?(col: IColumnDescriptor<T>): boolean
128
+ }
129
+
130
+ interface IColumnSetOptions {
131
+ table?: string | ITable | TableName
132
+ inherit?: boolean
133
+ duplicate?: 'error' | 'skip' | 'replace'
134
+ }
135
+
136
+ interface ITable {
137
+ schema?: string
138
+ table: string
139
+ }
140
+
141
+ type FormattingFilter = '^' | '~' | '#' | ':raw' | ':alias' | ':name' | ':json' | ':csv' | ':list' | ':value';
142
+
143
+ type QueryColumns<T> = Column<T> | ColumnSet<T> | Array<string | IColumnConfig<T> | Column<T>>;
144
+
145
+ type QueryParam =
146
+ string
147
+ | QueryFile
148
+ | IPreparedStatement
149
+ | IParameterizedQuery
150
+ | PreparedStatement
151
+ | ParameterizedQuery
152
+ | ((values?: any) => QueryParam);
153
+
154
+ type ValidSchema = string | string[] | null | void;
155
+
156
+ // helpers.TableName class;
157
+ // API: https://vitaly-t.github.io/pg-promise/helpers.TableName.html
158
+ class TableName {
159
+ constructor(table: string | ITable)
160
+
161
+ // these are all read-only:
162
+ readonly name: string;
163
+ readonly table: string;
164
+ readonly schema: string;
165
+
166
+ toString(): string
167
+ }
168
+
169
+ // helpers.Column class;
170
+ // API: https://vitaly-t.github.io/pg-promise/helpers.Column.html
171
+ class Column<T = unknown> {
172
+ constructor(col: string | IColumnConfig<T>);
173
+
174
+ // these are all read-only:
175
+ readonly name: string;
176
+ readonly prop: string;
177
+ readonly mod: FormattingFilter;
178
+ readonly cast: string;
179
+ readonly cnd: boolean;
180
+ readonly def: any;
181
+ readonly castText: string;
182
+ readonly escapedName: string;
183
+ readonly variable: string;
184
+ readonly init: (col: IColumnDescriptor<T>) => any
185
+ readonly skip: (col: IColumnDescriptor<T>) => boolean
186
+
187
+ toString(level?: number): string
188
+ }
189
+
190
+ // helpers.Column class;
191
+ // API: https://vitaly-t.github.io/pg-promise/helpers.ColumnSet.html
192
+ class ColumnSet<T = unknown> {
193
+ constructor(columns: Column<T>, options?: IColumnSetOptions)
194
+ constructor(columns: Array<string | IColumnConfig<T> | Column<T>>, options?: IColumnSetOptions)
195
+ constructor(columns: object, options?: IColumnSetOptions)
196
+
197
+ readonly columns: Column<T>[];
198
+ readonly names: string;
199
+ readonly table: TableName;
200
+ readonly variables: string;
201
+
202
+ assign(source?: { source?: object, prefix?: string }): string
203
+
204
+ assignColumns(options?: {
205
+ from?: string,
206
+ to?: string,
207
+ skip?: string | string[] | ((c: Column<T>) => boolean)
208
+ }): string
209
+
210
+ extend<K extends string>(columns: K[], opts?: {
211
+ skip?: boolean
212
+ }): ColumnSet<T & Record<K, unknown>>
213
+ extend<S>(columns: Column<S> | ColumnSet<S> | Array<IColumnConfig<S> | Column<S>>, opts?: {
214
+ skip?: boolean
215
+ }): ColumnSet<T & S>
216
+
217
+ merge<K extends string>(columns: K[]): ColumnSet<T & Record<K, unknown>>
218
+ merge<S>(columns: Column<S> | ColumnSet<S> | Array<IColumnConfig<S> | Column<S>>): ColumnSet<T & S>
219
+
220
+ prepare(obj: object): object
221
+
222
+ toString(level?: number): string
223
+ }
224
+
225
+ const minify: typeof pgMinify;
226
+
227
+ // Query Result Mask;
228
+ // API: https://vitaly-t.github.io/pg-promise/global.html#queryResult
229
+ enum queryResult {
230
+ one = 1,
231
+ many = 2,
232
+ none = 4,
233
+ any = 6
234
+ }
235
+
236
+ // PreparedStatement class;
237
+ // API: https://vitaly-t.github.io/pg-promise/PreparedStatement.html
238
+ class PreparedStatement {
239
+
240
+ constructor(options?: IPreparedStatement)
241
+
242
+ // standard properties:
243
+ name: string;
244
+ text: string | QueryFile;
245
+ values: any[];
246
+
247
+ // advanced properties:
248
+ binary: boolean;
249
+ rowMode: void | 'array';
250
+ rows: number;
251
+ types: pg.ITypes;
252
+
253
+ parse(): IPreparedParsed | errors.PreparedStatementError
254
+
255
+ toString(level?: number): string
256
+ }
257
+
258
+ // ParameterizedQuery class;
259
+ // API: https://vitaly-t.github.io/pg-promise/ParameterizedQuery.html
260
+ class ParameterizedQuery {
261
+
262
+ constructor(options?: string | QueryFile | IParameterizedQuery)
263
+
264
+ // standard properties:
265
+ text: string | QueryFile;
266
+ values: any[];
267
+
268
+ // advanced properties:
269
+ binary: boolean;
270
+ rowMode: void | 'array';
271
+ types: pg.ITypes;
272
+
273
+ parse(): IParameterizedParsed | errors.ParameterizedQueryError
274
+
275
+ toString(level?: number): string
276
+ }
277
+
278
+ // QueryFile class;
279
+ // API: https://vitaly-t.github.io/pg-promise/QueryFile.html
280
+ class QueryFile {
281
+ constructor(file: string, options?: IQueryFileOptions)
282
+
283
+ readonly error: Error;
284
+ readonly file: string;
285
+ readonly options: any;
286
+
287
+ prepare(): void
288
+
289
+ toString(level?: number): string
290
+ }
291
+
292
+ const txMode: typeof _txMode;
293
+ const utils: IUtils;
294
+ const as: IFormatting;
295
+
296
+ // Database full protocol;
297
+ // API: https://vitaly-t.github.io/pg-promise/Database.html
298
+ //
299
+ // We export this interface only to be able to help IntelliSense cast extension types correctly,
300
+ // which doesn't always work, depending on the version of IntelliSense being used.
301
+ interface IDatabase<Ext, C extends pg.IClient = pg.IClient> extends IBaseProtocol<Ext> {
302
+ connect(options?: IConnectionOptions<C>): Promise<IConnected<Ext, C>>
303
+
304
+ /////////////////////////////////////////////////////////////////////////////
305
+ // Hidden, read-only properties, for integrating with third-party libraries:
306
+
307
+ readonly $config: ILibConfig<Ext, C>
308
+ readonly $cn: string | pg.IConnectionParameters<C>
309
+ readonly $dc: any
310
+ readonly $pool: pg.IPool
311
+ }
312
+
313
+ interface IResultExt<T = unknown> extends pg.IResult<T> {
314
+ // Property 'duration' exists only in the following context:
315
+ // - for single-query events 'receive'
316
+ // - for method Database.result
317
+ duration?: number
318
+ }
319
+
320
+ // Post-initialization interface;
321
+ // API: https://vitaly-t.github.io/pg-promise/module-pg-promise.html
322
+ interface IMain<Ext = {}, C extends pg.IClient = pg.IClient> {
323
+ <T = Ext, C extends pg.IClient = pg.IClient>(cn: string | pg.IConnectionParameters<C>, dc?: any): IDatabase<T, C> & T
324
+
325
+ readonly PreparedStatement: typeof PreparedStatement
326
+ readonly ParameterizedQuery: typeof ParameterizedQuery
327
+ readonly QueryFile: typeof QueryFile
328
+ readonly queryResult: typeof queryResult
329
+ readonly minify: typeof pgMinify
330
+ readonly spex: ISpex
331
+ readonly errors: typeof errors
332
+ readonly utils: IUtils
333
+ readonly txMode: typeof txMode
334
+ readonly helpers: IHelpers
335
+ readonly as: IFormatting
336
+ readonly pg: typeof pg
337
+
338
+ end(): void
339
+ }
340
+
341
+ // Additional methods available inside tasks + transactions;
342
+ // API: https://vitaly-t.github.io/pg-promise/Task.html
343
+ interface ITask<Ext> extends IBaseProtocol<Ext>, ISpex {
344
+ readonly ctx: ITaskContext
345
+ }
346
+
347
+ interface ITaskIfOptions<Ext = {}> {
348
+ cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean)
349
+ tag?: any
350
+ }
351
+
352
+ interface ITxIfOptions<Ext = {}> extends ITaskIfOptions<Ext> {
353
+ mode?: _txMode.TransactionMode | null
354
+ reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean)
355
+ }
356
+
357
+ // Base database protocol
358
+ // API: https://vitaly-t.github.io/pg-promise/Database.html
359
+ interface IBaseProtocol<Ext> {
360
+
361
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#query
362
+ query<T = any>(query: QueryParam, values?: any, qrm?: queryResult): Promise<T>
363
+
364
+ // result-specific methods;
365
+
366
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#none
367
+ none(query: QueryParam, values?: any): Promise<null>
368
+
369
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#one
370
+ one<T = any>(query: QueryParam, values?: any, cb?: (value: any) => T, thisArg?: any): Promise<T>
371
+
372
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#oneOrNone
373
+ oneOrNone<T = any>(query: QueryParam, values?: any, cb?: (value: any) => T, thisArg?: any): Promise<T | null>
374
+
375
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#many
376
+ many<T = any>(query: QueryParam, values?: any): Promise<T[]>
377
+
378
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#manyOrNone
379
+ manyOrNone<T = any>(query: QueryParam, values?: any): Promise<T[]>
380
+
381
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#any
382
+ any<T = any>(query: QueryParam, values?: any): Promise<T[]>
383
+
384
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#result
385
+ result<T, R = IResultExt<T>>(query: QueryParam, values?: any, cb?: (value: IResultExt<T>) => R, thisArg?: any): Promise<R>
386
+
387
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#multiResult
388
+ multiResult(query: QueryParam, values?: any): Promise<pg.IResult[]>
389
+
390
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#multi
391
+ multi<T = any>(query: QueryParam, values?: any): Promise<Array<T[]>>
392
+
393
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#stream
394
+ stream(qs: NodeJS.ReadableStream, init: (stream: NodeJS.ReadableStream) => void): Promise<{
395
+ processed: number,
396
+ duration: number
397
+ }>
398
+
399
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#func
400
+ func<T = any>(funcName: string, values?: any, qrm?: queryResult): Promise<T>
401
+
402
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#proc
403
+ proc<T = any>(procName: string, values?: any, cb?: (value: any) => T, thisArg?: any): Promise<T | null>
404
+
405
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#map
406
+ map<T = any>(query: QueryParam, values: any, cb: (row: any, index: number, data: any[]) => T, thisArg?: any): Promise<T[]>
407
+
408
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#each
409
+ each<T = any>(query: QueryParam, values: any, cb: (row: any, index: number, data: any[]) => void, thisArg?: any): Promise<T[]>
410
+
411
+ // Tasks;
412
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#task
413
+ task<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
414
+
415
+ task<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
416
+
417
+ task<T>(options: { tag?: any }, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
418
+
419
+ // Conditional Tasks;
420
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#taskIf
421
+ taskIf<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
422
+
423
+ taskIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
424
+
425
+ taskIf<T>(options: ITaskIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
426
+
427
+ // Transactions;
428
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#tx
429
+ tx<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
430
+
431
+ tx<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
432
+
433
+ tx<T>(options: {
434
+ tag?: any,
435
+ mode?: _txMode.TransactionMode | null
436
+ }, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
437
+
438
+ // Conditional Transactions;
439
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#txIf
440
+ txIf<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
441
+
442
+ txIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
443
+
444
+ txIf<T>(options: ITxIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
445
+ }
446
+
447
+ // Database object in connected state;
448
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#connect
449
+ interface IConnected<Ext, C extends pg.IClient> extends IBaseProtocol<Ext>, ISpex {
450
+ readonly client: C
451
+
452
+ // Note that for normal connections (working with the pool), method `done` accepts `kill`
453
+ // flag to terminate the connection within the pool, so it can be auto-recreated;
454
+ // And in this case the method returns nothing / void.
455
+
456
+ // But for direct connections (connect({direct: true})), `kill` flag is ignored, because
457
+ // the connection is always closed physically, which may take time, and so in this case
458
+ // the method returns a Promise to indicate when the connection finished closing.
459
+ done(kill?: boolean): void | Promise<void>;
460
+
461
+ // Repeated calls are not allowed and will throw an error.
462
+ }
463
+
464
+ // Event context extension for tasks + transactions;
465
+ // See: https://vitaly-t.github.io/pg-promise/global.html#TaskContext
466
+ interface ITaskContext {
467
+
468
+ // these are set at the beginning of each task/transaction:
469
+ readonly context: any
470
+ readonly parent: ITaskContext | null
471
+ readonly connected: boolean
472
+ readonly inTransaction: boolean
473
+ readonly level: number
474
+ readonly useCount: number
475
+ readonly isTX: boolean
476
+ readonly start: Date
477
+ readonly tag: any
478
+ readonly dc: any
479
+
480
+ // these are set at the end of each task/transaction:
481
+ readonly finish?: Date
482
+ readonly duration?: number
483
+ readonly success?: boolean
484
+ readonly result?: any
485
+
486
+ // this exists only inside transactions (isTX = true):
487
+ readonly txLevel?: number
488
+
489
+ // Version of PostgreSQL Server to which we are connected;
490
+ // This property is not available with Native Bindings!
491
+ readonly serverVersion: string
492
+ }
493
+
494
+ // Generic Event Context interface;
495
+ // See: https://vitaly-t.github.io/pg-promise/global.html#EventContext
496
+ interface IEventContext<C extends pg.IClient = pg.IClient> {
497
+ client: C
498
+ cn: any
499
+ dc: any
500
+ query: any
501
+ params: any,
502
+ values: any,
503
+ queryFilePath?: string,
504
+ ctx: ITaskContext
505
+ }
506
+
507
+ // Errors namespace
508
+ // API: https://vitaly-t.github.io/pg-promise/errors.html
509
+ namespace errors {
510
+ // QueryResultError interface;
511
+ // API: https://vitaly-t.github.io/pg-promise/errors.QueryResultError.html
512
+ class QueryResultError extends Error {
513
+
514
+ // standard error properties:
515
+ name: string;
516
+ message: string;
517
+ stack: string;
518
+
519
+ // extended properties:
520
+ result: pg.IResult;
521
+ received: number;
522
+ code: queryResultErrorCode;
523
+ query: string;
524
+ values: any;
525
+
526
+ // API: https://vitaly-t.github.io/pg-promise/errors.QueryResultError.html#toString
527
+ toString(): string
528
+ }
529
+
530
+ // QueryFileError interface;
531
+ // API: https://vitaly-t.github.io/pg-promise/errors.QueryFileError.html
532
+ class QueryFileError extends Error {
533
+
534
+ // standard error properties:
535
+ name: string;
536
+ message: string;
537
+ stack: string;
538
+
539
+ // extended properties:
540
+ file: string;
541
+ options: IQueryFileOptions;
542
+ error: pgMinify.SQLParsingError;
543
+
544
+ toString(level?: number): string
545
+ }
546
+
547
+ // PreparedStatementError interface;
548
+ // API: https://vitaly-t.github.io/pg-promise/errors.PreparedStatementError.html
549
+ class PreparedStatementError extends Error {
550
+
551
+ // standard error properties:
552
+ name: string;
553
+ message: string;
554
+ stack: string;
555
+
556
+ // extended properties:
557
+ error: QueryFileError;
558
+
559
+ toString(level?: number): string
560
+ }
561
+
562
+ // ParameterizedQueryError interface;
563
+ // API: https://vitaly-t.github.io/pg-promise/errors.ParameterizedQueryError.html
564
+ class ParameterizedQueryError extends Error {
565
+
566
+ // standard error properties:
567
+ name: string;
568
+ message: string;
569
+ stack: string;
570
+
571
+ // extended properties:
572
+ error: QueryFileError;
573
+
574
+ toString(level?: number): string
575
+ }
576
+
577
+ // Query Result Error Code;
578
+ // API: https://vitaly-t.github.io/pg-promise/errors.html#.queryResultErrorCode
579
+ enum queryResultErrorCode {
580
+ noData = 0,
581
+ notEmpty = 1,
582
+ multiple = 2
583
+ }
584
+ }
585
+
586
+ // Library's Initialization Options
587
+ // API: https://vitaly-t.github.io/pg-promise/module-pg-promise.html
588
+ interface IInitOptions<Ext = {}, C extends pg.IClient = pg.IClient> {
589
+ noWarnings?: boolean
590
+ pgFormatting?: boolean
591
+ pgNative?: boolean
592
+ capSQL?: boolean
593
+ schema?: ValidSchema | ((dc: any) => ValidSchema)
594
+
595
+ connect?(e: { client: C, dc: any, useCount: number }): void
596
+
597
+ disconnect?(e: { client: C, dc: any }): void
598
+
599
+ query?(e: IEventContext<C>): void
600
+
601
+ // NOTE: The result is undefined when data comes from QueryStream, i.e. via method Database.stream
602
+ receive?(e: { data: any[], result: IResultExt | void, ctx: IEventContext<C> }): void
603
+
604
+ task?(e: IEventContext<C>): void
605
+
606
+ transact?(e: IEventContext<C>): void
607
+
608
+ error?(err: any, e: IEventContext<C>): void
609
+
610
+ extend?(obj: IDatabase<Ext, C> & Ext, dc: any): void
611
+ }
612
+
613
+ // API: https://vitaly-t.github.io/pg-promise/Database.html#$config
614
+ interface ILibConfig<Ext, C extends pg.IClient = pg.IClient> {
615
+ version: string
616
+ promise: IGenericPromise
617
+ options: IInitOptions<Ext, C>
618
+ pgp: IMain<Ext, C>
619
+ $npm: any
620
+ }
621
+
622
+ // Custom-Type Formatting object
623
+ // API: https://github.com/vitaly-t/pg-promise#custom-type-formatting
624
+ interface ICTFObject {
625
+ toPostgres(a: any): any
626
+ }
627
+
628
+ // Query formatting namespace;
629
+ // API: https://vitaly-t.github.io/pg-promise/formatting.html
630
+ interface IFormatting {
631
+
632
+ ctf: { toPostgres: symbol, rawType: symbol }
633
+
634
+ alias(name: string | (() => string)): string
635
+
636
+ array(arr: any[] | (() => any[]), options?: { capSQL?: boolean }): string
637
+
638
+ bool(value: any | (() => any)): string
639
+
640
+ buffer(obj: object | (() => object), raw?: boolean): string
641
+
642
+ csv(values: any | (() => any)): string
643
+
644
+ date(d: Date | (() => Date), raw?: boolean): string
645
+
646
+ format(query: string | QueryFile | ICTFObject, values?: any, options?: IFormattingOptions): string
647
+
648
+ func(func: (cc: any) => any, raw?: boolean, cc?: any): string
649
+
650
+ json(data: any | (() => any), raw?: boolean): string
651
+
652
+ name(name: any | (() => any)): string
653
+
654
+ number(value: number | bigint | (() => number | bigint)): string
655
+
656
+ text(value: any | (() => any), raw?: boolean): string
657
+
658
+ value(value: any | (() => any)): string
659
+ }
660
+
661
+ interface ITaskArguments<T> extends IArguments {
662
+ options: { tag?: any, cnd?: any, mode?: _txMode.TransactionMode | null } & T
663
+
664
+ cb(): any
665
+ }
666
+
667
+ // General-purpose functions
668
+ // API: https://vitaly-t.github.io/pg-promise/utils.html
669
+ interface IUtils {
670
+ camelize(text: string): string
671
+
672
+ camelizeVar(text: string): string
673
+
674
+ enumSql(dir: string, options?: {
675
+ recursive?: boolean,
676
+ ignoreErrors?: boolean
677
+ }, cb?: (file: string, name: string, path: string) => any): any
678
+
679
+ taskArgs<T = {}>(args: IArguments): ITaskArguments<T>
680
+ }
681
+
682
+ // Query Formatting Helpers
683
+ // API: https://vitaly-t.github.io/pg-promise/helpers.html
684
+ interface IHelpers {
685
+
686
+ concat(queries: Array<string | QueryFile | {
687
+ query: string | QueryFile,
688
+ values?: any,
689
+ options?: IFormattingOptions
690
+ }>): string
691
+
692
+ insert(data: object | object[], columns?: QueryColumns<any> | null, table?: string | ITable | TableName): string
693
+
694
+ update(data: object | object[], columns?: QueryColumns<any> | null, table?: string | ITable | TableName, options?: {
695
+ tableAlias?: string,
696
+ valueAlias?: string,
697
+ emptyUpdate?: any
698
+ }): any
699
+
700
+ values(data: object | object[], columns?: QueryColumns<any> | null): string
701
+
702
+ sets(data: object, columns?: QueryColumns<any> | null): string
703
+
704
+ Column: typeof Column
705
+ ColumnSet: typeof ColumnSet
706
+ TableName: typeof TableName
707
+
708
+ _TN(path: TemplateStringsArray, ...args: Array<any>): ITable
709
+
710
+ _TN(path: string): ITable
711
+ }
712
+
713
+ interface IGenericPromise {
714
+ (cb: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void): Promise<any>
715
+
716
+ resolve(value?: any): void
717
+
718
+ reject(reason?: any): void
719
+
720
+ all(iterable: any): Promise<any>
721
+ }
722
+ }
723
+
724
+ // Default library interface (before initialization)
725
+ // API: https://vitaly-t.github.io/pg-promise/module-pg-promise.html
726
+ declare function pgPromise<Ext = {}, C extends pg.IClient = pg.IClient>(options?: pgPromise.IInitOptions<Ext, C>): pgPromise.IMain<Ext, C>
727
+
728
+ export = pgPromise;