pg-promise 11.7.8 → 11.9.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.
|
@@ -168,9 +168,8 @@ npm.utils.addInspection(TableName, function () {
|
|
|
168
168
|
* @see {@link helpers.TableName TableName}, {@link external:TemplateStringsArray TemplateStringsArray}
|
|
169
169
|
*/
|
|
170
170
|
function _TN(path, ...args) {
|
|
171
|
-
if (Array.isArray(path)
|
|
172
|
-
|
|
173
|
-
path = path.reduce((a, c, i) => a + c + v(i), '');
|
|
171
|
+
if (Array.isArray(path)) {
|
|
172
|
+
path = path.reduce((a, c, i) => a + c + (args[i] ?? ''), '');
|
|
174
173
|
} // else 'path' is a string
|
|
175
174
|
const [schema, table] = path.split('.');
|
|
176
175
|
if (table === undefined) {
|
package/lib/main.js
CHANGED
|
@@ -36,6 +36,7 @@ const npm = {
|
|
|
36
36
|
* @param {array} [options.values] - See property {@link ParameterizedQuery#values values}.
|
|
37
37
|
* @param {boolean} [options.binary] - See property {@link ParameterizedQuery#binary binary}.
|
|
38
38
|
* @param {string} [options.rowMode] - See property {@link ParameterizedQuery#rowMode rowMode}.
|
|
39
|
+
* @param {ITypes} [options.types] - See property {@link ParameterizedQuery#types types}.
|
|
39
40
|
*
|
|
40
41
|
* @returns {ParameterizedQuery}
|
|
41
42
|
*
|
|
@@ -91,7 +92,7 @@ class ParameterizedQuery extends ServerFormatting {
|
|
|
91
92
|
text: options
|
|
92
93
|
};
|
|
93
94
|
} else {
|
|
94
|
-
options = assert(options, ['text', 'values', 'binary', 'rowMode']);
|
|
95
|
+
options = assert(options, ['text', 'values', 'binary', 'rowMode', 'types']);
|
|
95
96
|
}
|
|
96
97
|
super(options);
|
|
97
98
|
}
|
|
@@ -148,6 +149,10 @@ ParameterizedQuery.prototype.parse = function () {
|
|
|
148
149
|
_i.target.rowMode = options.rowMode;
|
|
149
150
|
}
|
|
150
151
|
|
|
152
|
+
if (options.types !== undefined) {
|
|
153
|
+
_i.target.types = options.types;
|
|
154
|
+
}
|
|
155
|
+
|
|
151
156
|
if (errors.length) {
|
|
152
157
|
return _i.currentError = new ParameterizedQueryError(errors[0], _i.target);
|
|
153
158
|
}
|
|
@@ -238,6 +243,14 @@ module.exports = {ParameterizedQuery};
|
|
|
238
243
|
* - `array` will make all data rows arrive as arrays of values. By default, rows arrive as objects.
|
|
239
244
|
*/
|
|
240
245
|
|
|
246
|
+
/**
|
|
247
|
+
* @name ParameterizedQuery#types
|
|
248
|
+
* @type {ITypes}
|
|
249
|
+
* @default undefined
|
|
250
|
+
* @description
|
|
251
|
+
* Custom type parsers just for this query result.
|
|
252
|
+
*/
|
|
253
|
+
|
|
241
254
|
/**
|
|
242
255
|
* @name ParameterizedQuery#error
|
|
243
256
|
* @type {errors.ParameterizedQueryError}
|
|
@@ -38,6 +38,7 @@ const npm = {
|
|
|
38
38
|
* @param {boolean} [options.binary] - See property {@link PreparedStatement#binary binary}.
|
|
39
39
|
* @param {string} [options.rowMode] - See property {@link PreparedStatement#rowMode rowMode}.
|
|
40
40
|
* @param {number} [options.rows] - See property {@link PreparedStatement#rows rows}.
|
|
41
|
+
* @param {ITypes} [options.types] - See property {@link PreparedStatement#types types}.
|
|
41
42
|
*
|
|
42
43
|
* @returns {PreparedStatement}
|
|
43
44
|
*
|
|
@@ -89,7 +90,7 @@ const npm = {
|
|
|
89
90
|
*/
|
|
90
91
|
class PreparedStatement extends ServerFormatting {
|
|
91
92
|
constructor(options) {
|
|
92
|
-
options = assert(options, ['name', 'text', 'values', 'binary', 'rowMode', 'rows']);
|
|
93
|
+
options = assert(options, ['name', 'text', 'values', 'binary', 'rowMode', 'rows', 'types']);
|
|
93
94
|
super(options);
|
|
94
95
|
}
|
|
95
96
|
|
|
@@ -192,6 +193,10 @@ PreparedStatement.prototype.parse = function () {
|
|
|
192
193
|
_i.target.rows = options.rows;
|
|
193
194
|
}
|
|
194
195
|
|
|
196
|
+
if (options.types !== undefined) {
|
|
197
|
+
_i.target.types = options.types;
|
|
198
|
+
}
|
|
199
|
+
|
|
195
200
|
if (errors.length) {
|
|
196
201
|
return _i.currentError = new PreparedStatementError(errors[0], _i.target);
|
|
197
202
|
}
|
|
@@ -289,6 +294,14 @@ module.exports = {PreparedStatement};
|
|
|
289
294
|
* - `array` will make all data rows arrive as arrays of values. By default, rows arrive as objects.
|
|
290
295
|
*/
|
|
291
296
|
|
|
297
|
+
/**
|
|
298
|
+
* @name PreparedStatement#types
|
|
299
|
+
* @type {ITypes}
|
|
300
|
+
* @default undefined
|
|
301
|
+
* @description
|
|
302
|
+
* Custom type parsers just for this query result.
|
|
303
|
+
*/
|
|
304
|
+
|
|
292
305
|
/**
|
|
293
306
|
* @name PreparedStatement#error
|
|
294
307
|
* @type {errors.PreparedStatementError}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-promise",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.9.0",
|
|
4
4
|
"description": "PostgreSQL interface for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "typescript/pg-promise.d.ts",
|
|
@@ -42,24 +42,24 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"assert-options": "0.8.1",
|
|
45
|
-
"pg": "8.
|
|
45
|
+
"pg": "8.12.0",
|
|
46
46
|
"pg-minify": "1.6.4",
|
|
47
47
|
"spex": "3.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@eslint/js": "9.
|
|
51
|
-
"@types/node": "20.
|
|
50
|
+
"@eslint/js": "9.6.0",
|
|
51
|
+
"@types/node": "20.14.9",
|
|
52
52
|
"bluebird": "3.7.2",
|
|
53
53
|
"coveralls": "3.1.1",
|
|
54
|
-
"cspell": "8.
|
|
55
|
-
"eslint": "9.
|
|
56
|
-
"globals": "15.
|
|
54
|
+
"cspell": "8.10.0",
|
|
55
|
+
"eslint": "9.6.0",
|
|
56
|
+
"globals": "15.8.0",
|
|
57
57
|
"istanbul": "0.4.5",
|
|
58
58
|
"jasmine-node": "3.0.0",
|
|
59
59
|
"jsdoc": "4.0.3",
|
|
60
60
|
"JSONStream": "1.3.5",
|
|
61
|
-
"pg-query-stream": "4.
|
|
61
|
+
"pg-query-stream": "4.6.0",
|
|
62
62
|
"tslint": "6.1.3",
|
|
63
|
-
"typescript": "5.
|
|
63
|
+
"typescript": "5.5.3"
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
// Follow the links below:
|
|
16
16
|
// https://stackoverflow.com/questions/36593087/using-a-custom-promise-as-a-generic-type
|
|
17
17
|
// https://github.com/Microsoft/TypeScript/issues/1213
|
|
18
|
+
|
|
18
19
|
type XPromise<T> = Promise<T>;
|
|
19
20
|
|
|
20
21
|
import * as pg from './pg-subset';
|
|
@@ -79,6 +80,7 @@ declare namespace pgPromise {
|
|
|
79
80
|
binary?: boolean
|
|
80
81
|
rowMode?: 'array' | null | void
|
|
81
82
|
rows?: number
|
|
83
|
+
types?: pg.ITypes
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
interface IParameterizedQuery {
|
|
@@ -86,6 +88,7 @@ declare namespace pgPromise {
|
|
|
86
88
|
values?: any[]
|
|
87
89
|
binary?: boolean
|
|
88
90
|
rowMode?: void | 'array'
|
|
91
|
+
types?: pg.ITypes;
|
|
89
92
|
}
|
|
90
93
|
|
|
91
94
|
interface IPreparedParsed {
|
|
@@ -248,6 +251,7 @@ declare namespace pgPromise {
|
|
|
248
251
|
binary: boolean;
|
|
249
252
|
rowMode: void | 'array';
|
|
250
253
|
rows: number;
|
|
254
|
+
types: pg.ITypes;
|
|
251
255
|
|
|
252
256
|
parse(): IPreparedParsed | errors.PreparedStatementError
|
|
253
257
|
|
|
@@ -267,6 +271,7 @@ declare namespace pgPromise {
|
|
|
267
271
|
// advanced properties:
|
|
268
272
|
binary: boolean;
|
|
269
273
|
rowMode: void | 'array';
|
|
274
|
+
types: pg.ITypes;
|
|
270
275
|
|
|
271
276
|
parse(): IParameterizedParsed | errors.ParameterizedQueryError
|
|
272
277
|
|
|
@@ -349,6 +354,16 @@ declare namespace pgPromise {
|
|
|
349
354
|
readonly ctx: ITaskContext
|
|
350
355
|
}
|
|
351
356
|
|
|
357
|
+
interface ITaskIfOptions<Ext = {}> {
|
|
358
|
+
cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean)
|
|
359
|
+
tag?: any
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
interface ITxIfOptions<Ext = {}> extends ITaskIfOptions<Ext> {
|
|
363
|
+
mode?: _txMode.TransactionMode | null
|
|
364
|
+
reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean)
|
|
365
|
+
}
|
|
366
|
+
|
|
352
367
|
// Base database protocol
|
|
353
368
|
// API: https://vitaly-t.github.io/pg-promise/Database.html
|
|
354
369
|
interface IBaseProtocol<Ext> {
|
|
@@ -405,46 +420,38 @@ declare namespace pgPromise {
|
|
|
405
420
|
|
|
406
421
|
// Tasks;
|
|
407
422
|
// API: https://vitaly-t.github.io/pg-promise/Database.html#task
|
|
408
|
-
task<T
|
|
423
|
+
task<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
409
424
|
|
|
410
|
-
task<T
|
|
425
|
+
task<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
411
426
|
|
|
412
|
-
task<T
|
|
427
|
+
task<T>(options: { tag?: any }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
413
428
|
|
|
414
429
|
// Conditional Tasks;
|
|
415
430
|
// API: https://vitaly-t.github.io/pg-promise/Database.html#taskIf
|
|
416
|
-
taskIf<T
|
|
431
|
+
taskIf<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
417
432
|
|
|
418
|
-
taskIf<T
|
|
433
|
+
taskIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
419
434
|
|
|
420
|
-
taskIf<T
|
|
421
|
-
tag?: any,
|
|
422
|
-
cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean)
|
|
423
|
-
}, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
435
|
+
taskIf<T>(options: ITaskIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
424
436
|
|
|
425
437
|
// Transactions;
|
|
426
438
|
// API: https://vitaly-t.github.io/pg-promise/Database.html#tx
|
|
427
|
-
tx<T
|
|
439
|
+
tx<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
428
440
|
|
|
429
|
-
tx<T
|
|
441
|
+
tx<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
430
442
|
|
|
431
|
-
tx<T
|
|
443
|
+
tx<T>(options: {
|
|
432
444
|
tag?: any,
|
|
433
445
|
mode?: _txMode.TransactionMode | null
|
|
434
446
|
}, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
435
447
|
|
|
436
448
|
// Conditional Transactions;
|
|
437
449
|
// API: https://vitaly-t.github.io/pg-promise/Database.html#txIf
|
|
438
|
-
txIf<T
|
|
450
|
+
txIf<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
439
451
|
|
|
440
|
-
txIf<T
|
|
452
|
+
txIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
441
453
|
|
|
442
|
-
txIf<T
|
|
443
|
-
tag?: any,
|
|
444
|
-
mode?: _txMode.TransactionMode | null,
|
|
445
|
-
reusable?: boolean | ((t: ITask<Ext> & Ext) => boolean),
|
|
446
|
-
cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean)
|
|
447
|
-
}, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
454
|
+
txIf<T>(options: ITxIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
|
|
448
455
|
}
|
|
449
456
|
|
|
450
457
|
// Database object in connected state;
|
|
@@ -709,7 +716,8 @@ declare namespace pgPromise {
|
|
|
709
716
|
TableName: typeof TableName
|
|
710
717
|
|
|
711
718
|
_TN(path: TemplateStringsArray, ...args: Array<any>): ITable
|
|
712
|
-
|
|
719
|
+
|
|
720
|
+
_TN(path: string): ITable
|
|
713
721
|
}
|
|
714
722
|
|
|
715
723
|
interface IGenericPromise {
|