pg-promise 10.12.0 → 10.14.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.
- package/lib/formatting.js +6 -6
- package/lib/query.js +12 -0
- package/package.json +5 -5
- package/typescript/README.MD +1 -1
- package/typescript/pg-promise.d.ts +2 -2
- package/typescript/pg-subset.d.ts +6 -6
package/lib/formatting.js
CHANGED
|
@@ -98,7 +98,7 @@ function formatValue({value, fm, cc, options}) {
|
|
|
98
98
|
if (value instanceof Date) {
|
|
99
99
|
return $to.date(value, isRaw);
|
|
100
100
|
}
|
|
101
|
-
if (value
|
|
101
|
+
if (Array.isArray(value)) {
|
|
102
102
|
return $to.array(value, options);
|
|
103
103
|
}
|
|
104
104
|
if (value instanceof Buffer) {
|
|
@@ -115,9 +115,9 @@ function formatValue({value, fm, cc, options}) {
|
|
|
115
115
|
// Arrays of any depth/dimension are supported.
|
|
116
116
|
//
|
|
117
117
|
// Top-level empty arrays are formatted as literal '{}' to avoid the necessity of explicit type casting,
|
|
118
|
-
// as the server cannot automatically infer type of an empty non-literal array.
|
|
118
|
+
// as the server cannot automatically infer the type of an empty non-literal array.
|
|
119
119
|
function formatArray(array, options) {
|
|
120
|
-
const loop = a => `[` + a.map(value => value
|
|
120
|
+
const loop = a => `[` + a.map(value => Array.isArray(value) ? loop(value) : formatValue({
|
|
121
121
|
value,
|
|
122
122
|
options
|
|
123
123
|
})).join() + `]`;
|
|
@@ -128,7 +128,7 @@ function formatArray(array, options) {
|
|
|
128
128
|
///////////////////////////////////////////////////////////////////
|
|
129
129
|
// Formats array/object/value as a list of comma-separated values.
|
|
130
130
|
function formatCSV(values, options) {
|
|
131
|
-
if (values
|
|
131
|
+
if (Array.isArray(values)) {
|
|
132
132
|
return values.map(value => formatValue({value, options})).join();
|
|
133
133
|
}
|
|
134
134
|
if (typeof values === `object` && values !== null) {
|
|
@@ -291,7 +291,7 @@ function formatQuery(query, values, raw, options) {
|
|
|
291
291
|
return formatQuery(query, resolveFunc(ctf.toPostgres, values), raw || ctf.rawType, options);
|
|
292
292
|
}
|
|
293
293
|
if (typeof values === `object` && values !== null) {
|
|
294
|
-
if (values
|
|
294
|
+
if (Array.isArray(values)) {
|
|
295
295
|
// $1, $2,... formatting to be applied;
|
|
296
296
|
return formatAs.array({query, array: values, raw, options});
|
|
297
297
|
}
|
|
@@ -688,7 +688,7 @@ const $as = {
|
|
|
688
688
|
if (isNull(arr)) {
|
|
689
689
|
return `null`;
|
|
690
690
|
}
|
|
691
|
-
if (arr
|
|
691
|
+
if (Array.isArray(arr)) {
|
|
692
692
|
return $to.array(arr, options);
|
|
693
693
|
}
|
|
694
694
|
throw new TypeError(`${wrapText(arr)} is not an Array object.`);
|
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.0",
|
|
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.
|
|
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.8.
|
|
58
|
+
"typescript": "4.8.4"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/typescript/README.MD
CHANGED
|
@@ -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.
|
|
@@ -290,7 +290,7 @@ declare namespace pgPromise {
|
|
|
290
290
|
readonly $pool: pg.IPool
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
interface IResultExt extends pg.IResult {
|
|
293
|
+
interface IResultExt<T = unknown> extends pg.IResult<T> {
|
|
294
294
|
// Property 'duration' exists only in the following context:
|
|
295
295
|
// - for single-query events 'receive'
|
|
296
296
|
// - for method Database.result
|
|
@@ -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
|