pg-promise 12.1.2 → 12.2.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/README.md +1 -1
- package/lib/database.js +6 -26
- package/lib/formatting.js +2 -2
- package/lib/query.js +2 -2
- package/lib/special-query.js +1 -1
- package/lib/stream.js +1 -1
- package/lib/task.js +2 -7
- package/lib/tx-mode.js +5 -5
- package/lib/types/prepared-statement.js +1 -1
- package/lib/utils/color.js +2 -2
- package/lib/utils/index.js +6 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ pg-promise
|
|
|
3
3
|
|
|
4
4
|
[](https://github.com/vitaly-t/pg-promise/actions/workflows/ci.yml)
|
|
5
5
|
[](https://nodejs.org)
|
|
6
|
-
[](https://www.postgresql.org)
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
package/lib/database.js
CHANGED
|
@@ -18,7 +18,7 @@ const npm = {
|
|
|
18
18
|
utils: require('./utils'),
|
|
19
19
|
pubUtils: require('./utils/public'),
|
|
20
20
|
connect: require('./connect'),
|
|
21
|
-
query: require('./query'),
|
|
21
|
+
query: require('./query').query,
|
|
22
22
|
task: require('./task'),
|
|
23
23
|
text: require('./text')
|
|
24
24
|
};
|
|
@@ -1233,30 +1233,11 @@ function Database(cn, dc, config) {
|
|
|
1233
1233
|
*
|
|
1234
1234
|
* @example
|
|
1235
1235
|
*
|
|
1236
|
-
* db.task('my-task', t => {
|
|
1236
|
+
* db.task('my-task', async t => {
|
|
1237
1237
|
* // t.ctx = task context object
|
|
1238
1238
|
*
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1241
|
-
* return t.any('SELECT * FROM Events WHERE userId = $1', user.id);
|
|
1242
|
-
* });
|
|
1243
|
-
* })
|
|
1244
|
-
* .then(data => {
|
|
1245
|
-
* // success
|
|
1246
|
-
* // data = as returned from the task's callback
|
|
1247
|
-
* })
|
|
1248
|
-
* .catch(error => {
|
|
1249
|
-
* // error
|
|
1250
|
-
* });
|
|
1251
|
-
*
|
|
1252
|
-
* @example
|
|
1253
|
-
*
|
|
1254
|
-
* // using an ES7 syntax for the callback:
|
|
1255
|
-
* db.task('my-task', async t {
|
|
1256
|
-
* // t.ctx = task context object
|
|
1257
|
-
*
|
|
1258
|
-
* const user = await t.one('SELECT id FROM Users WHERE name = $1', 'John');
|
|
1259
|
-
* return t.any('SELECT * FROM Events WHERE userId = $1', user.id);
|
|
1239
|
+
* const user = await t.one('SELECT id FROM Users WHERE name = $1', ['John']);
|
|
1240
|
+
* return t.any('SELECT * FROM Events WHERE userId = $1', [user.id]);
|
|
1260
1241
|
* })
|
|
1261
1242
|
* .then(data => {
|
|
1262
1243
|
* // success
|
|
@@ -1419,7 +1400,7 @@ function Database(cn, dc, config) {
|
|
|
1419
1400
|
* @example
|
|
1420
1401
|
*
|
|
1421
1402
|
* // using an ES7 syntax for the callback:
|
|
1422
|
-
* db.tx('my-transaction', async t {
|
|
1403
|
+
* db.tx('my-transaction', async t => {
|
|
1423
1404
|
* // t.ctx = transaction context object
|
|
1424
1405
|
*
|
|
1425
1406
|
* const user = await t.one('INSERT INTO Users(name, age) VALUES($1, $2) RETURNING id', ['Mike', 25]);
|
|
@@ -1432,7 +1413,6 @@ function Database(cn, dc, config) {
|
|
|
1432
1413
|
* .catch(error => {
|
|
1433
1414
|
* // error
|
|
1434
1415
|
* });
|
|
1435
|
-
*
|
|
1436
1416
|
*/
|
|
1437
1417
|
obj.tx = function () {
|
|
1438
1418
|
const args = npm.pubUtils.taskArgs(arguments);
|
|
@@ -1612,7 +1592,7 @@ function onError(err) {
|
|
|
1612
1592
|
module.exports = config => {
|
|
1613
1593
|
const npmLocal = config.$npm;
|
|
1614
1594
|
npmLocal.connect = npmLocal.connect || npm.connect(config);
|
|
1615
|
-
npmLocal.query = npmLocal.query || npm.query
|
|
1595
|
+
npmLocal.query = npmLocal.query || npm.query;
|
|
1616
1596
|
npmLocal.task = npmLocal.task || npm.task(config);
|
|
1617
1597
|
return Database;
|
|
1618
1598
|
};
|
package/lib/formatting.js
CHANGED
|
@@ -110,7 +110,7 @@ function formatValue({value, fm, cc, options}) {
|
|
|
110
110
|
|
|
111
111
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
112
112
|
// Converts array of values into PostgreSQL Array Constructor: array[...], as per PostgreSQL documentation:
|
|
113
|
-
//
|
|
113
|
+
// https://www.postgresql.org/docs/17/arrays.html
|
|
114
114
|
//
|
|
115
115
|
// Arrays of any depth/dimension are supported.
|
|
116
116
|
//
|
|
@@ -888,7 +888,7 @@ const $to = {
|
|
|
888
888
|
return num < 0 ? `(${s})` : s;
|
|
889
889
|
}
|
|
890
890
|
// Converting NaN/+Infinity/-Infinity according to Postgres documentation:
|
|
891
|
-
//
|
|
891
|
+
// https://www.postgresql.org/docs/17/datatype-numeric.html#DATATYPE-FLOAT
|
|
892
892
|
//
|
|
893
893
|
// NOTE: strings for 'NaN'/'+Infinity'/'-Infinity' are not case-sensitive.
|
|
894
894
|
if (num === Number.POSITIVE_INFINITY) {
|
package/lib/query.js
CHANGED
|
@@ -18,7 +18,7 @@ const npm = {
|
|
|
18
18
|
utils: require('./utils'),
|
|
19
19
|
formatting: require('./formatting'),
|
|
20
20
|
errors: require('./errors'),
|
|
21
|
-
stream: require('./stream'),
|
|
21
|
+
stream: require('./stream').stream,
|
|
22
22
|
text: require('./text')
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -270,4 +270,4 @@ function makeIterable(r) {
|
|
|
270
270
|
};
|
|
271
271
|
}
|
|
272
272
|
|
|
273
|
-
module.exports =
|
|
273
|
+
module.exports = {query: $query};
|
package/lib/special-query.js
CHANGED
package/lib/stream.js
CHANGED
package/lib/task.js
CHANGED
|
@@ -13,7 +13,7 @@ const npm = {
|
|
|
13
13
|
spex: require('spex'),
|
|
14
14
|
utils: require('./utils'),
|
|
15
15
|
mode: require('./tx-mode'),
|
|
16
|
-
query: require('./query'),
|
|
16
|
+
query: require('./query').query,
|
|
17
17
|
text: require('./text')
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -323,13 +323,8 @@ const execute = (ctx, obj, isTX, config) => {
|
|
|
323
323
|
|
|
324
324
|
module.exports = config => {
|
|
325
325
|
const npmLocal = config.$npm;
|
|
326
|
-
|
|
327
|
-
// istanbul ignore next:
|
|
328
|
-
// we keep 'npm.query' initialization here, even though it is always
|
|
329
|
-
// pre-initialized by the 'database' module, for integrity purpose.
|
|
330
|
-
npmLocal.query = npmLocal.query || npm.query();
|
|
326
|
+
npmLocal.query = npmLocal.query || npm.query;
|
|
331
327
|
npmLocal.spex = npmLocal.spex || npm.spex;
|
|
332
|
-
|
|
333
328
|
return {
|
|
334
329
|
Task, execute, callback
|
|
335
330
|
};
|
package/lib/tx-mode.js
CHANGED
|
@@ -25,16 +25,16 @@ const isolationLevel = {
|
|
|
25
25
|
/** Isolation level not specified. */
|
|
26
26
|
none: 0,
|
|
27
27
|
|
|
28
|
-
/** ISOLATION LEVEL SERIALIZABLE */
|
|
28
|
+
/** `ISOLATION LEVEL SERIALIZABLE` */
|
|
29
29
|
serializable: 1,
|
|
30
30
|
|
|
31
|
-
/** ISOLATION LEVEL REPEATABLE READ */
|
|
31
|
+
/** `ISOLATION LEVEL REPEATABLE READ` */
|
|
32
32
|
repeatableRead: 2,
|
|
33
33
|
|
|
34
|
-
/** ISOLATION LEVEL READ COMMITTED */
|
|
34
|
+
/** `ISOLATION LEVEL READ COMMITTED` */
|
|
35
35
|
readCommitted: 3
|
|
36
36
|
|
|
37
|
-
// From the official documentation:
|
|
37
|
+
// From the official documentation: https://www.postgresql.org/docs/17/sql-set-transaction.html
|
|
38
38
|
// The SQL standard defines one additional level, READ UNCOMMITTED. In PostgreSQL READ UNCOMMITTED is treated as READ COMMITTED.
|
|
39
39
|
// => skipping `READ UNCOMMITTED`.
|
|
40
40
|
};
|
|
@@ -120,7 +120,7 @@ class TransactionMode extends InnerState {
|
|
|
120
120
|
accessMode = 'read write';
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
// From the official documentation:
|
|
123
|
+
// From the official documentation: https://www.postgresql.org/docs/17/sql-set-transaction.html
|
|
124
124
|
// The DEFERRABLE transaction property has no effect unless the transaction is also SERIALIZABLE and READ ONLY
|
|
125
125
|
if (tiLevel === isolationLevel.serializable && readOnly) {
|
|
126
126
|
if (deferrable) {
|
|
@@ -44,7 +44,7 @@ const npm = {
|
|
|
44
44
|
*
|
|
45
45
|
* @see
|
|
46
46
|
* {@link errors.PreparedStatementError PreparedStatementError},
|
|
47
|
-
* {@link
|
|
47
|
+
* {@link https://www.postgresql.org/docs/17/sql-prepare.html PostgreSQL Prepared Statements}
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
50
|
*
|
package/lib/utils/color.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const {format} = require('util');
|
|
2
2
|
|
|
3
3
|
class ColorConsole {
|
|
4
4
|
|
|
@@ -41,7 +41,7 @@ class ColorConsole {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
static formatColor(args, color) {
|
|
44
|
-
return args.map(a => `\x1b[${color}m${
|
|
44
|
+
return args.map(a => `\x1b[${color}m${format(a)}\x1b[0m`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
package/lib/utils/index.js
CHANGED
|
@@ -57,11 +57,11 @@ function addReadProp(obj, name, value, hidden) {
|
|
|
57
57
|
|
|
58
58
|
//////////////////////////////////////////////////////////////
|
|
59
59
|
// Converts a connection string or object into its safe copy:
|
|
60
|
-
// if password is present, it is masked with symbol '#'.
|
|
60
|
+
// if a password is present, it is masked with the symbol '#'.
|
|
61
61
|
function getSafeConnection(cn) {
|
|
62
62
|
const maskPassword = cs => cs.replace(/:(?![/])([^@]+)/, (_, m) => ':' + new Array(m.length + 1).join('#'));
|
|
63
63
|
if (typeof cn === 'object') {
|
|
64
|
-
const copy =
|
|
64
|
+
const copy = {...cn};
|
|
65
65
|
if (typeof copy.password === 'string') {
|
|
66
66
|
copy.password = copy.password.replace(/./g, '#');
|
|
67
67
|
}
|
|
@@ -88,7 +88,7 @@ function inherits(child, parent) {
|
|
|
88
88
|
// istanbul ignore next
|
|
89
89
|
function getLocalStack(startIdx, maxLines) {
|
|
90
90
|
// from the call stack, we take up to maximum lines,
|
|
91
|
-
// starting with specified line index:
|
|
91
|
+
// starting with the specified line index:
|
|
92
92
|
startIdx = startIdx || 0;
|
|
93
93
|
const endIdx = maxLines > 0 ? startIdx + maxLines : undefined;
|
|
94
94
|
return new Error().stack
|
|
@@ -105,8 +105,8 @@ function InternalError(error) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/////////////////////////////////////////////////////////////////
|
|
108
|
-
// Parses a property name
|
|
109
|
-
// if the property exists. Returns object {valid, has, target, value}:
|
|
108
|
+
// Parses a property name and gets its name from the object
|
|
109
|
+
// if the property exists. Returns an object {valid, has, target, value}:
|
|
110
110
|
// - valid - true/false, whether the syntax is valid
|
|
111
111
|
// - has - a flag that property exists; set when 'valid' = true
|
|
112
112
|
// - target - the target object that contains the property; set when 'has' = true
|
|
@@ -169,7 +169,7 @@ function isConnectivityError(err) {
|
|
|
169
169
|
// Class 08 - Connection Exception (except for 08P01, for protocol violation).
|
|
170
170
|
// Class 57 - Operator Intervention (except for 57014, for cancelled queries).
|
|
171
171
|
//
|
|
172
|
-
// ERROR CODES: https://www.postgresql.org/docs/
|
|
172
|
+
// ERROR CODES: https://www.postgresql.org/docs/17/errcodes-appendix.html
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
///////////////////////////////////////////////////////////////
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-promise",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "PostgreSQL interface for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "typescript/pg-promise.d.ts",
|
|
@@ -50,16 +50,16 @@
|
|
|
50
50
|
"pg-query-stream": "4.10.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@eslint/js": "9.
|
|
54
|
-
"@types/node": "24.
|
|
53
|
+
"@eslint/js": "9.36.0",
|
|
54
|
+
"@types/node": "24.6.1",
|
|
55
55
|
"coveralls": "3.1.1",
|
|
56
56
|
"cspell": "9.2.1",
|
|
57
|
-
"eslint": "9.
|
|
58
|
-
"globals": "16.
|
|
57
|
+
"eslint": "9.36.0",
|
|
58
|
+
"globals": "16.4.0",
|
|
59
59
|
"istanbul": "0.4.5",
|
|
60
60
|
"jasmine-node": "3.0.0",
|
|
61
61
|
"jsdoc": "4.0.4",
|
|
62
62
|
"JSONStream": "1.3.5",
|
|
63
|
-
"typescript": "5.9.
|
|
63
|
+
"typescript": "5.9.3"
|
|
64
64
|
}
|
|
65
65
|
}
|