pg-promise 10.12.1 → 10.14.1
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.
- package/lib/query.js +12 -0
- package/package.json +5 -5
- package/typescript/pg-promise.d.ts +28 -32
- package/typescript/pg-subset.d.ts +6 -6
package/lib/query.js
CHANGED
|
@@ -167,12 +167,14 @@ function $query(ctx, query, values, qrm, config) {
|
|
|
167
167
|
lastResult = result[result.length - 1];
|
|
168
168
|
for (let i = 0; i < result.length; i++) {
|
|
169
169
|
const r = result[i];
|
|
170
|
+
makeIterable(r);
|
|
170
171
|
error = Events.receive(opt, r.rows, r, getContext());
|
|
171
172
|
if (error) {
|
|
172
173
|
break;
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
176
|
} else {
|
|
177
|
+
makeIterable(result);
|
|
176
178
|
result.duration = Date.now() - start;
|
|
177
179
|
error = Events.receive(opt, result.rows, result, getContext());
|
|
178
180
|
}
|
|
@@ -258,6 +260,16 @@ function $query(ctx, query, values, qrm, config) {
|
|
|
258
260
|
});
|
|
259
261
|
}
|
|
260
262
|
|
|
263
|
+
// Extends Result to provide iterable for the rows;
|
|
264
|
+
//
|
|
265
|
+
// To be removed once the following PR is merged amd released:
|
|
266
|
+
// https://github.com/brianc/node-postgres/pull/2861
|
|
267
|
+
function makeIterable(r) {
|
|
268
|
+
r[Symbol.iterator] = function () {
|
|
269
|
+
return this.rows.values();
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
261
273
|
module.exports = config => {
|
|
262
274
|
return function (ctx, query, values, qrm) {
|
|
263
275
|
return $query.call(this, ctx, query, values, qrm, config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-promise",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.14.1",
|
|
4
4
|
"description": "PostgreSQL interface for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "typescript/pg-promise.d.ts",
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
"spex": "3.2.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/node": "18.11.
|
|
48
|
+
"@types/node": "18.11.9",
|
|
49
49
|
"bluebird": "3.7.2",
|
|
50
50
|
"coveralls": "3.1.1",
|
|
51
|
-
"eslint": "8.
|
|
51
|
+
"eslint": "8.27.0",
|
|
52
52
|
"istanbul": "0.4.5",
|
|
53
53
|
"jasmine-node": "3.0.0",
|
|
54
|
-
"jsdoc": "
|
|
54
|
+
"jsdoc": "4.0.0",
|
|
55
55
|
"JSONStream": "1.3.5",
|
|
56
56
|
"pg-query-stream": "4.2.4",
|
|
57
57
|
"tslint": "6.1.3",
|
|
58
|
-
"typescript": "4.
|
|
58
|
+
"typescript": "4.9.3"
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/////////////////////////////////////////
|
|
11
|
-
// Requires pg-promise v10.
|
|
11
|
+
// Requires pg-promise v10.14.0 or later.
|
|
12
12
|
/////////////////////////////////////////
|
|
13
13
|
|
|
14
14
|
// We use ES6 as static promise here, because generic promises are still not supported.
|
|
@@ -21,6 +21,26 @@ import * as pg from './pg-subset';
|
|
|
21
21
|
import * as pgMinify from 'pg-minify';
|
|
22
22
|
import * as spexLib from 'spex';
|
|
23
23
|
|
|
24
|
+
// internal namespace for "txMode" property:
|
|
25
|
+
declare namespace _txMode {
|
|
26
|
+
// Transaction Isolation Level;
|
|
27
|
+
// API: http://vitaly-t.github.io/pg-promise/txMode.html#.isolationLevel
|
|
28
|
+
enum isolationLevel {
|
|
29
|
+
none = 0,
|
|
30
|
+
serializable = 1,
|
|
31
|
+
repeatableRead = 2,
|
|
32
|
+
readCommitted = 3
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// TransactionMode class;
|
|
36
|
+
// API: http://vitaly-t.github.io/pg-promise/txMode.TransactionMode.html
|
|
37
|
+
class TransactionMode {
|
|
38
|
+
constructor(options?: { tiLevel?: isolationLevel, readOnly?: boolean, deferrable?: boolean })
|
|
39
|
+
|
|
40
|
+
begin(cap?: boolean): string
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
24
44
|
// Main protocol of the library;
|
|
25
45
|
// API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html
|
|
26
46
|
declare namespace pgPromise {
|
|
@@ -269,7 +289,7 @@ declare namespace pgPromise {
|
|
|
269
289
|
constructor(api: IPromiseConfig)
|
|
270
290
|
}
|
|
271
291
|
|
|
272
|
-
const txMode:
|
|
292
|
+
const txMode: typeof _txMode;
|
|
273
293
|
const utils: IUtils;
|
|
274
294
|
const as: IFormatting;
|
|
275
295
|
|
|
@@ -290,7 +310,7 @@ declare namespace pgPromise {
|
|
|
290
310
|
readonly $pool: pg.IPool
|
|
291
311
|
}
|
|
292
312
|
|
|
293
|
-
interface IResultExt extends pg.IResult {
|
|
313
|
+
interface IResultExt<T = unknown> extends pg.IResult<T> {
|
|
294
314
|
// Property 'duration' exists only in the following context:
|
|
295
315
|
// - for single-query events 'receive'
|
|
296
316
|
// - for method Database.result
|
|
@@ -311,7 +331,7 @@ declare namespace pgPromise {
|
|
|
311
331
|
readonly spex: spexLib.ISpex
|
|
312
332
|
readonly errors: typeof errors
|
|
313
333
|
readonly utils: IUtils
|
|
314
|
-
readonly txMode:
|
|
334
|
+
readonly txMode: typeof txMode
|
|
315
335
|
readonly helpers: IHelpers
|
|
316
336
|
readonly as: IFormatting
|
|
317
337
|
readonly pg: typeof pg
|
|
@@ -353,7 +373,7 @@ declare namespace pgPromise {
|
|
|
353
373
|
any<T = any>(query: QueryParam, values?: any): XPromise<T[]>
|
|
354
374
|
|
|
355
375
|
// API: http://vitaly-t.github.io/pg-promise/Database.html#result
|
|
356
|
-
result<T = IResultExt
|
|
376
|
+
result<T, R = IResultExt<T>>(query: QueryParam, values?: any, cb?: (value: IResultExt<T>) => R, thisArg?: any): XPromise<R>
|
|
357
377
|
|
|
358
378
|
// API: http://vitaly-t.github.io/pg-promise/Database.html#multiResult
|
|
359
379
|
multiResult(query: QueryParam, values?: any): XPromise<pg.IResult[]>
|
|
@@ -398,7 +418,7 @@ declare namespace pgPromise {
|
|
|
398
418
|
|
|
399
419
|
tx<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
400
420
|
|
|
401
|
-
tx<T = any>(options: { tag?: any, mode?: TransactionMode | null }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
421
|
+
tx<T = any>(options: { tag?: any, mode?: _txMode.TransactionMode | null }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
402
422
|
|
|
403
423
|
// Conditional Transactions;
|
|
404
424
|
// API: http://vitaly-t.github.io/pg-promise/Database.html#txIf
|
|
@@ -406,7 +426,7 @@ declare namespace pgPromise {
|
|
|
406
426
|
|
|
407
427
|
txIf<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
408
428
|
|
|
409
|
-
txIf<T = any>(options: { tag?: any, mode?: TransactionMode | null, reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean), cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean) }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
429
|
+
txIf<T = any>(options: { tag?: any, mode?: _txMode.TransactionMode | null, reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean), cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean) }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
410
430
|
}
|
|
411
431
|
|
|
412
432
|
// Database object in connected state;
|
|
@@ -546,23 +566,6 @@ declare namespace pgPromise {
|
|
|
546
566
|
}
|
|
547
567
|
}
|
|
548
568
|
|
|
549
|
-
// Transaction Isolation Level;
|
|
550
|
-
// API: http://vitaly-t.github.io/pg-promise/txMode.html#.isolationLevel
|
|
551
|
-
enum isolationLevel {
|
|
552
|
-
none = 0,
|
|
553
|
-
serializable = 1,
|
|
554
|
-
repeatableRead = 2,
|
|
555
|
-
readCommitted = 3
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// TransactionMode class;
|
|
559
|
-
// API: http://vitaly-t.github.io/pg-promise/txMode.TransactionMode.html
|
|
560
|
-
class TransactionMode {
|
|
561
|
-
constructor(options?: { tiLevel?: isolationLevel, readOnly?: boolean, deferrable?: boolean })
|
|
562
|
-
|
|
563
|
-
begin(cap?: boolean): string
|
|
564
|
-
}
|
|
565
|
-
|
|
566
569
|
// Library's Initialization Options
|
|
567
570
|
// API: http://vitaly-t.github.io/pg-promise/module-pg-promise.html
|
|
568
571
|
interface IInitOptions<Ext = {}, C extends pg.IClient = pg.IClient> {
|
|
@@ -641,15 +644,8 @@ declare namespace pgPromise {
|
|
|
641
644
|
value(value: any | (() => any)): string
|
|
642
645
|
}
|
|
643
646
|
|
|
644
|
-
// Transaction Mode namespace;
|
|
645
|
-
// API: http://vitaly-t.github.io/pg-promise/txMode.html
|
|
646
|
-
interface ITXMode {
|
|
647
|
-
isolationLevel: typeof isolationLevel
|
|
648
|
-
TransactionMode: typeof TransactionMode
|
|
649
|
-
}
|
|
650
|
-
|
|
651
647
|
interface ITaskArguments<T> extends IArguments {
|
|
652
|
-
options: { tag?: any, cnd?: any, mode?: TransactionMode | null } & T
|
|
648
|
+
options: { tag?: any, cnd?: any, mode?: _txMode.TransactionMode | null } & T
|
|
653
649
|
|
|
654
650
|
cb(): any
|
|
655
651
|
}
|
|
@@ -39,10 +39,10 @@ declare namespace pg {
|
|
|
39
39
|
format: string
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
interface IResult {
|
|
42
|
+
interface IResult<T = unknown> extends Iterable<T> {
|
|
43
43
|
command: string
|
|
44
44
|
rowCount: number
|
|
45
|
-
rows:
|
|
45
|
+
rows: T[]
|
|
46
46
|
fields: IColumn[]
|
|
47
47
|
|
|
48
48
|
// properties below are not available within Native Bindings:
|
|
@@ -290,13 +290,13 @@ declare namespace pg {
|
|
|
290
290
|
|
|
291
291
|
interface IClient extends EventEmitter {
|
|
292
292
|
|
|
293
|
-
query(config: any, values: any[], callback: (err: Error, result: IResult) => void): undefined
|
|
293
|
+
query<T>(config: any, values: any[], callback: (err: Error, result: IResult<T>) => void): undefined
|
|
294
294
|
|
|
295
|
-
query(config: any, callback: (err: Error, result: IResult) => void): undefined
|
|
295
|
+
query<T>(config: any, callback: (err: Error, result: IResult<T>) => void): undefined
|
|
296
296
|
|
|
297
|
-
query(config: any, values: any[]): Promise<IResult
|
|
297
|
+
query<T>(config: any, values: any[]): Promise<IResult<T>>
|
|
298
298
|
|
|
299
|
-
query(config: any): Promise<IResult
|
|
299
|
+
query<T>(config: any): Promise<IResult<T>>
|
|
300
300
|
|
|
301
301
|
connectionParameters: IConnectionParameters
|
|
302
302
|
database: string
|