pg-promise 11.14.0 → 12.0.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 CHANGED
@@ -2,7 +2,7 @@ pg-promise
2
2
  ==========
3
3
 
4
4
  [![Build Status](https://github.com/vitaly-t/pg-promise/actions/workflows/ci.yml/badge.svg)](https://github.com/vitaly-t/pg-promise/actions/workflows/ci.yml)
5
- [![Node Version](https://img.shields.io/badge/nodejs-14%20--%2024-green.svg?logo=node.js&style=flat)](https://nodejs.org)
5
+ [![Node Version](https://img.shields.io/badge/nodejs-16%20--%2024-green.svg?logo=node.js&style=flat)](https://nodejs.org)
6
6
  [![Postgres Version](https://img.shields.io/badge/postgresql-10%20--%2016-green.svg?logo=postgresql&style=flat)](https://www.postgresql.org)
7
7
 
8
8
  ---
@@ -52,7 +52,6 @@ Built on top of [node-postgres], this library adds the following:
52
52
  * Declarative approach to handling query results
53
53
  * Global events reporting for central handling
54
54
  * Extensive support for external SQL files
55
- * Support for all promise libraries
56
55
 
57
56
  At its inception in 2015, this library was only adding promises to the base driver, hence the name `pg-promise`.
58
57
  And while the original name was kept, the library's functionality was vastly extended, with promises now being
@@ -999,7 +998,7 @@ to force the pool to shut down all the connections it holds:
999
998
  db.$pool.end(); // shuts down the connection pool associated with the Database object
1000
999
  ```
1001
1000
 
1002
- For example, if you are using the [Bluebird] library, you can chain the last promise in the process like this:
1001
+ For example, you can chain the last promise in the process like this:
1003
1002
 
1004
1003
  ```js
1005
1004
  .finally(db.$pool.end);
@@ -1117,7 +1116,6 @@ See the relevant API: [pgp.end], [Database.$pool]
1117
1116
  <!-- External Links -->
1118
1117
 
1119
1118
  [node-postgres]:https://github.com/brianc/node-postgres
1120
- [Bluebird]:https://github.com/petkaantonov/bluebird
1121
1119
  [SQL injection]:https://en.wikipedia.org/wiki/SQL_injection
1122
1120
  [Symbol]:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
1123
1121
  [idleTimeoutMillis]:https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/defaults.js
package/lib/connect.js CHANGED
@@ -16,8 +16,8 @@ const npm = {
16
16
  formatting: require('./formatting')
17
17
  };
18
18
 
19
- function poolConnect(ctx, db, config) {
20
- return config.promise((resolve, reject) => {
19
+ function poolConnect(ctx, db) {
20
+ return new Promise((resolve, reject) => {
21
21
  const p = db.$pool;
22
22
  if (p.ending) {
23
23
  db.$destroy();
@@ -37,7 +37,7 @@ function poolConnect(ctx, db, config) {
37
37
  reject(err);
38
38
  } else {
39
39
  if ('$useCount' in client) {
40
- // Make sure useCount drops to 1, if it ever reaches maximum integer number;
40
+ // Make sure useCount drops to 1, if it ever reaches the maximum integer number;
41
41
  // We do not drop it to zero, to avoid rerun of initialization queries that
42
42
  // usually check for useCount === 0;
43
43
  // istanbul ignore if
@@ -75,7 +75,7 @@ function poolConnect(ctx, db, config) {
75
75
  }
76
76
 
77
77
  function directConnect(ctx, config) {
78
- return config.promise((resolve, reject) => {
78
+ return new Promise((resolve, reject) => {
79
79
  const client = new config.pgp.pg.Client(ctx.cn);
80
80
  client.connect(err => {
81
81
  if (err) {
@@ -94,7 +94,7 @@ function directConnect(ctx, config) {
94
94
  useCount: 0,
95
95
  release() {
96
96
  client.end = end;
97
- const p = config.promise((res, rej) => client.end().then(res).catch(rej));
97
+ const p = new Promise((res, rej) => client.end().then(res).catch(rej));
98
98
  Events.disconnect(ctx, client);
99
99
  client.removeListener('error', onError);
100
100
  return p;
@@ -173,6 +173,6 @@ function setSchema(client, ctx) {
173
173
  }
174
174
 
175
175
  module.exports = config => ({
176
- pool: (ctx, db) => poolConnect(ctx, db, config),
176
+ pool: (ctx, db) => poolConnect(ctx, db),
177
177
  direct: ctx => directConnect(ctx, config)
178
178
  });
package/lib/database.js CHANGED
@@ -122,7 +122,6 @@ const npm = {
122
122
  function Database(cn, dc, config) {
123
123
 
124
124
  const dbThis = this,
125
- $p = config.promise,
126
125
  poolConnection = typeof cn === 'string' ? {connectionString: cn} : cn,
127
126
  pool = new config.pgp.pg.Pool(poolConnection),
128
127
  endMethod = pool.end;
@@ -249,7 +248,7 @@ function Database(cn, dc, config) {
249
248
  const self = {
250
249
  query(query, values, qrm) {
251
250
  if (!ctx.db) {
252
- return $p.reject(new Error(npm.text.queryDisconnected));
251
+ return Promise.reject(new Error(npm.text.queryDisconnected));
253
252
  }
254
253
  return config.$npm.query.call(this, ctx, query, values, qrm);
255
254
  },
@@ -338,7 +337,7 @@ function Database(cn, dc, config) {
338
337
  })
339
338
  .catch(error => {
340
339
  ctx.disconnect();
341
- return $p.reject(error);
340
+ return Promise.reject(error);
342
341
  });
343
342
  };
344
343
 
@@ -351,27 +350,8 @@ function Database(cn, dc, config) {
351
350
  * Properties available in the object:
352
351
  * - `pgp` - instance of the entire library after initialization
353
352
  * - `options` - the library's {@link module:pg-promise Initialization Options} object
354
- * - `promiseLib` - instance of the promise library that's used
355
- * - `promise` - generic promise interface that uses `promiseLib` via 4 basic methods:
356
- * - `promise((resolve, reject) => {})` - to create a new promise
357
- * - `promise.resolve(value)` - to resolve with a value
358
- * - `promise.reject(reason)` - to reject with a reason
359
- * - `promise.all(iterable)` - to resolve an iterable list of promises
360
353
  * - `version` - this library's version
361
354
  * - `$npm` _(hidden property)_ - internal module cache
362
- *
363
- * @example
364
- *
365
- * // Using the promise protocol as configured by pg-promise:
366
- *
367
- * const $p = db.$config.promise;
368
- *
369
- * const resolvedPromise = $p.resolve('some data');
370
- * const rejectedPromise = $p.reject('some reason');
371
- *
372
- * const newPromise = $p((resolve, reject) => {
373
- * // call either resolve(data) or reject(reason) here
374
- * });
375
355
  */
376
356
  npm.utils.addReadProp(this, '$config', config, true);
377
357
 
@@ -1353,12 +1333,12 @@ function Database(cn, dc, config) {
1353
1333
  if ('cnd' in args.options) {
1354
1334
  cnd = typeof cnd === 'function' ? cnd.call(obj, obj) : !!cnd;
1355
1335
  } else {
1356
- cnd = !obj.ctx; // create task, if it is the top level
1336
+ cnd = !obj.ctx; // create a task if it is the top level
1357
1337
  }
1358
- // reusable only if condition fails, and not top-level:
1338
+ // reusable only if the condition fails, and not top-level:
1359
1339
  args.options.reusable = !cnd && !!obj.ctx;
1360
1340
  } catch (e) {
1361
- return $p.reject(e);
1341
+ return Promise.reject(e);
1362
1342
  }
1363
1343
  return taskProcessor.call(this, args, false);
1364
1344
  };
@@ -1541,17 +1521,17 @@ function Database(cn, dc, config) {
1541
1521
  const reusable = args.options.reusable;
1542
1522
  args.options.reusable = !cnd && obj.ctx && typeof reusable === 'function' ? reusable.call(obj, obj) : !!reusable;
1543
1523
  } catch (e) {
1544
- return $p.reject(e);
1524
+ return Promise.reject(e);
1545
1525
  }
1546
1526
  return taskProcessor.call(this, args, args.options.cnd);
1547
1527
  };
1548
1528
 
1549
1529
  // Task method;
1550
- // Resolves with result from the callback function;
1530
+ // Resolves with the result from the callback function;
1551
1531
  function taskProcessor(params, isTX) {
1552
1532
 
1553
1533
  if (typeof params.cb !== 'function') {
1554
- return $p.reject(new TypeError('Callback function is required.'));
1534
+ return Promise.reject(new TypeError('Callback function is required.'));
1555
1535
  }
1556
1536
 
1557
1537
  if (params.options.reusable) {
@@ -1595,12 +1575,12 @@ function Database(cn, dc, config) {
1595
1575
  })
1596
1576
  .catch(error => {
1597
1577
  taskCtx.disconnect();
1598
- return $p.reject(error);
1578
+ return Promise.reject(error);
1599
1579
  });
1600
1580
  }
1601
1581
 
1602
1582
  function addServerVersion(target, client) {
1603
- // Exclude else-case from coverage, because it can only occur with Native Bindings.
1583
+ // Exclude else-case from the coverage because it can only occur with Native Bindings.
1604
1584
  // istanbul ignore else
1605
1585
  if (client.serverVersion) {
1606
1586
  npm.utils.addReadProp(target, 'serverVersion', client.serverVersion);
@@ -1632,7 +1612,7 @@ function onError(err) {
1632
1612
  module.exports = config => {
1633
1613
  const npmLocal = config.$npm;
1634
1614
  npmLocal.connect = npmLocal.connect || npm.connect(config);
1635
- npmLocal.query = npmLocal.query || npm.query(config);
1615
+ npmLocal.query = npmLocal.query || npm.query();
1636
1616
  npmLocal.task = npmLocal.task || npm.task(config);
1637
1617
  return Database;
1638
1618
  };
package/lib/events.js CHANGED
@@ -531,7 +531,6 @@ module.exports = {Events};
531
531
  * It is set for all events.
532
532
  *
533
533
  * @property {string|undefined} queryFilePath
534
- * **Added in v11.14**<br/>
535
534
  * File path of a {@link QueryFile}, if the query comes from an external SQL file.
536
535
  * This is set only when the query originates from a {@link QueryFile} and only for events {@link event:query query} and {@link event:error error}.
537
536
  *
package/lib/index.js CHANGED
@@ -12,17 +12,18 @@ var v = process.versions.node.split('.'),
12
12
  highVer = +v[0];
13
13
 
14
14
  // istanbul ignore next
15
- if (highVer < 14) {
15
+ if (highVer < 16) {
16
16
 
17
- // From pg-promise v11.0.0, the oldest supported Node.js is v14.0.0
17
+ // From pg-promise v11.15.0, the oldest supported Node.js is v16.0.0
18
18
 
19
- // Node.js v12.0.0 was supported up to pg-promise v10.15.4
20
- // Node.js v8.0.0 was supported up to pg-promise v10.14.2
19
+ // Node.js v14.x was supported up to pg-promise v11.14.0
20
+ // Node.js v12.x was supported up to pg-promise v10.15.4
21
+ // Node.js v8.x was supported up to pg-promise v10.14.2
21
22
  // Node.js v7.6.0 was supported up to pg-promise v10.3.5
22
23
  // Node.js v4.5.0 was supported up to pg-promise v8.7.5
23
24
  // Node.js v0.10 was supported up to pg-promise v5.5.8
24
25
 
25
- throw new Error('Minimum Node.js version supported by pg-promise is 14.0.0');
26
+ throw new Error('Minimum Node.js version supported by pg-promise is 16.0.0');
26
27
  }
27
28
 
28
29
  module.exports = require('./main');
package/lib/main.js CHANGED
@@ -7,12 +7,10 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- const {PromiseAdapter} = require('./promise-adapter');
11
10
  const {DatabasePool} = require('./database-pool');
12
11
  const {PreparedStatement, ParameterizedQuery} = require('./types');
13
12
  const {QueryFile} = require('./query-file');
14
13
  const {queryResult} = require('./query-result');
15
- const {parsePromise} = require('./promise-parser');
16
14
  const {assert} = require('./assert');
17
15
 
18
16
  const npm = {
@@ -36,7 +34,7 @@ let originalClientConnect;
36
34
  * @module pg-promise
37
35
  *
38
36
  * @description
39
- * ## pg-promise v11.14
37
+ * ## pg-promise v12.0
40
38
  * All documentation here is for the latest official release only.
41
39
  *
42
40
  * ### Initialization Options
@@ -69,25 +67,6 @@ let originalClientConnect;
69
67
  *
70
68
  * This is a static option (can only be set prior to initialization).
71
69
  *
72
- * @property {object|function} [options.promiseLib=Promise]
73
- * Overrides the default (ES6 Promise) promise library for its internal use.
74
- *
75
- * Example below sets to use $[Bluebird] - the best and recommended promise library. It is the fastest one,
76
- * and supports $[Long Stack Traces], essential for debugging promises.
77
- *
78
- * ```js
79
- * const Promise = require('bluebird');
80
- * const initOptions = {
81
- * promiseLib: Promise
82
- * };
83
- * const pgp = require('pg-promise')(initOptions);
84
- * ```
85
- *
86
- * All existing promise libraries are supported. The ones with recognizable signature are used automatically,
87
- * while the rest can be configured via the $[Promise Adapter].
88
- *
89
- * This is a static option (can only be set prior to initialization).
90
- *
91
70
  * @property {boolean} [options.capSQL=false]
92
71
  * Capitalizes any SQL generated by the library.
93
72
  *
@@ -178,22 +157,18 @@ let originalClientConnect;
178
157
  */
179
158
  function $main(options) {
180
159
 
181
- options = assert(options, ['pgFormatting', 'pgNative', 'promiseLib', 'capSQL', 'noWarnings',
160
+ options = assert(options, ['pgFormatting', 'pgNative', 'capSQL', 'noWarnings',
182
161
  'connect', 'disconnect', 'query', 'receive', 'task', 'transact', 'error', 'extend', 'schema']);
183
162
 
184
163
  let pg = npm.pg;
185
- const p = parsePromise(options.promiseLib);
186
164
 
187
165
  const config = {
188
- version: npm.package.version,
189
- promiseLib: p.promiseLib,
190
- promise: p.promise
166
+ version: npm.package.version
191
167
  };
192
168
 
193
169
  npm.utils.addReadProp(config, '$npm', {}, true);
194
170
 
195
171
  // Locking properties that cannot be changed later:
196
- npm.utils.addReadProp(options, 'promiseLib', options.promiseLib);
197
172
  npm.utils.addReadProp(options, 'pgNative', !!options.pgNative);
198
173
 
199
174
  config.options = options;
@@ -235,7 +210,7 @@ function $main(options) {
235
210
  /**
236
211
  * @member {external:PG} pg
237
212
  * @description
238
- * Instance of the $[pg] library that's being used, depending on initialization option `pgNative`:
213
+ * Instance of the $[pg] library being used, depending on initialization option `pgNative`:
239
214
  * - regular `pg` module instance, without option `pgNative`, or equal to `false` (default)
240
215
  * - `pg` module instance with $[Native Bindings], if option `pgNative` was set.
241
216
  *
@@ -328,16 +303,6 @@ const rootNameSpace = {
328
303
  */
329
304
  queryResult,
330
305
 
331
- /**
332
- * @member {PromiseAdapter} PromiseAdapter
333
- * @readonly
334
- * @description
335
- * {@link PromiseAdapter} class.
336
- *
337
- * Available as `pgp.PromiseAdapter`, before and after initializing the library.
338
- */
339
- PromiseAdapter,
340
-
341
306
  /**
342
307
  * @member {ParameterizedQuery} ParameterizedQuery
343
308
  * @readonly
package/lib/query.js CHANGED
@@ -30,13 +30,12 @@ const badMask = queryResult.one | queryResult.many; // unsupported combination b
30
30
 
31
31
  //////////////////////////////
32
32
  // Generic query method;
33
- function $query(ctx, query, values, qrm, config) {
33
+ function $query(ctx, query, values, qrm) {
34
34
 
35
35
  const special = qrm instanceof SpecialQuery && qrm;
36
- const $p = config.promise;
37
36
 
38
37
  if (special && special.isStream) {
39
- return npm.stream.call(this, ctx, query, values, config);
38
+ return npm.stream.call(this, ctx, query, values);
40
39
  }
41
40
 
42
41
  const opt = ctx.options,
@@ -122,7 +121,7 @@ function $query(ctx, query, values, qrm, config) {
122
121
 
123
122
  if (!error && (!pgFormatting || entityType)) {
124
123
  try {
125
- // use 'pg-promise' implementation of values formatting;
124
+ // use 'pg-promise' implementation of value formatting;
126
125
  if (entityType) {
127
126
  params = undefined;
128
127
  query = npm.formatting.formatEntity(query, values, {capSQL, type: entityType});
@@ -143,7 +142,7 @@ function $query(ctx, query, values, qrm, config) {
143
142
  }
144
143
  }
145
144
 
146
- return $p((resolve, reject) => {
145
+ return new Promise((resolve, reject) => {
147
146
 
148
147
  if (notifyReject()) {
149
148
  return;
@@ -194,7 +193,7 @@ function $query(ctx, query, values, qrm, config) {
194
193
  const len = data.length;
195
194
  if (len) {
196
195
  if (len > 1 && qrm & queryResult.one) {
197
- // one row was expected, but returned multiple;
196
+ // one row was expected but returned multiple;
198
197
  error = new QueryResultError(qrec.multiple, lastResult, query, params);
199
198
  } else {
200
199
  if (!(qrm & (queryResult.one | queryResult.many))) {
@@ -271,8 +270,4 @@ function makeIterable(r) {
271
270
  };
272
271
  }
273
272
 
274
- module.exports = config => {
275
- return function (ctx, query, values, qrm) {
276
- return $query.call(this, ctx, query, values, qrm, config);
277
- };
278
- };
273
+ module.exports = () => $query;
package/lib/stream.js CHANGED
@@ -17,28 +17,26 @@ const npm = {
17
17
  ////////////////////////////////////////////
18
18
  // Streams query data into any destination,
19
19
  // with the help of pg-query-stream library.
20
- function $stream(ctx, qs, initCB, config) {
21
-
22
- const $p = config.promise;
20
+ function $stream(ctx, qs, initCB) {
23
21
 
24
22
  // istanbul ignore next:
25
23
  // we do not provide code coverage for the Native Bindings specifics
26
24
  if (ctx.options.pgNative) {
27
- return $p.reject(new Error(npm.text.nativeStreaming));
25
+ return Promise.reject(new Error(npm.text.nativeStreaming));
28
26
  }
29
27
  // Stream class was renamed again, see the following issue:
30
28
  // https://github.com/brianc/node-postgres/issues/2412
31
29
  if (!qs || !qs.constructor || qs.constructor.name !== 'QueryStream') {
32
30
  // invalid or missing stream object;
33
- return $p.reject(new TypeError(npm.text.invalidStream));
31
+ return Promise.reject(new TypeError(npm.text.invalidStream));
34
32
  }
35
33
  if (qs._reading || qs._closed) {
36
34
  // stream object is in the wrong state;
37
- return $p.reject(new Error(npm.text.invalidStreamState));
35
+ return Promise.reject(new Error(npm.text.invalidStreamState));
38
36
  }
39
37
  if (typeof initCB !== 'function') {
40
38
  // parameter `initCB` must be passed as the initialization callback;
41
- return $p.reject(new TypeError(npm.text.invalidStreamCB));
39
+ return Promise.reject(new TypeError(npm.text.invalidStreamCB));
42
40
  }
43
41
 
44
42
  let error = Events.query(ctx.options, getContext());
@@ -46,7 +44,7 @@ function $stream(ctx, qs, initCB, config) {
46
44
  if (error) {
47
45
  error = getError(error);
48
46
  Events.error(ctx.options, error, getContext());
49
- return $p.reject(error);
47
+ return Promise.reject(error);
50
48
  }
51
49
 
52
50
  const stream = ctx.db.client.query(qs);
@@ -61,7 +59,7 @@ function $stream(ctx, qs, initCB, config) {
61
59
  release();
62
60
  error = getError(e);
63
61
  Events.error(ctx.options, error, getContext());
64
- return $p.reject(error);
62
+ return Promise.reject(error);
65
63
  }
66
64
 
67
65
  const start = Date.now();
@@ -117,7 +115,7 @@ function $stream(ctx, qs, initCB, config) {
117
115
  };
118
116
  }
119
117
 
120
- return $p((res, rej) => {
118
+ return new Promise((res, rej) => {
121
119
  resolve = res;
122
120
  reject = rej;
123
121
  });
package/lib/task.js CHANGED
@@ -61,8 +61,6 @@ const npm = {
61
61
  */
62
62
  function Task(ctx, tag, isTX, config) {
63
63
 
64
- const $p = config.promise;
65
-
66
64
  /**
67
65
  * @member {TaskContext} Task#ctx
68
66
  * @readonly
@@ -112,7 +110,7 @@ function Task(ctx, tag, isTX, config) {
112
110
  // generic query method;
113
111
  this.query = function (query, values, qrm) {
114
112
  if (!ctx.db) {
115
- return $p.reject(new Error(npm.text.looseQuery));
113
+ return Promise.reject(new Error(npm.text.looseQuery));
116
114
  }
117
115
  return config.$npm.query.call(this, ctx, query, values, qrm);
118
116
  };
@@ -191,9 +189,8 @@ function Task(ctx, tag, isTX, config) {
191
189
  * @param config
192
190
  * @returns {Promise.<TResult>}
193
191
  */
194
- const callback = (ctx, obj, cb, config) => {
192
+ const callback = (ctx, obj, cb) => {
195
193
 
196
- const $p = config.promise;
197
194
  let result;
198
195
 
199
196
  try {
@@ -209,12 +206,12 @@ const callback = (ctx, obj, cb, config) => {
209
206
  dc: ctx.dc,
210
207
  ctx: ctx.ctx
211
208
  });
212
- return $p.reject(err); // reject with the error;
209
+ return Promise.reject(err); // reject with the error;
213
210
  }
214
211
  if (result && typeof result.then === 'function') {
215
212
  return result; // result is a valid promise object;
216
213
  }
217
- return $p.resolve(result);
214
+ return Promise.resolve(result);
218
215
  };
219
216
 
220
217
  /**
@@ -230,8 +227,6 @@ const callback = (ctx, obj, cb, config) => {
230
227
  */
231
228
  const execute = (ctx, obj, isTX, config) => {
232
229
 
233
- const $p = config.promise;
234
-
235
230
  // updates the task context and notifies the client;
236
231
  function update(start, success, result) {
237
232
  const c = ctx.ctx;
@@ -276,7 +271,7 @@ const execute = (ctx, obj, isTX, config) => {
276
271
  return cbData;
277
272
  }
278
273
  update(false, false, cbReason);
279
- return $p.reject(cbReason);
274
+ return Promise.reject(cbReason);
280
275
  },
281
276
  err => {
282
277
  // either COMMIT or ROLLBACK has failed, which is impossible
@@ -284,7 +279,7 @@ const execute = (ctx, obj, isTX, config) => {
284
279
  // istanbul ignore next:
285
280
  update(false, false, err);
286
281
  // istanbul ignore next:
287
- return $p.reject(err);
282
+ return Promise.reject(err);
288
283
  }),
289
284
  err => {
290
285
  // BEGIN has failed, which is impossible to replicate in a test
@@ -292,7 +287,7 @@ const execute = (ctx, obj, isTX, config) => {
292
287
  // istanbul ignore next:
293
288
  update(false, false, err);
294
289
  // istanbul ignore next:
295
- return $p.reject(err);
290
+ return Promise.reject(err);
296
291
  });
297
292
  }
298
293
 
@@ -326,7 +321,7 @@ const execute = (ctx, obj, isTX, config) => {
326
321
  })
327
322
  .catch(error => {
328
323
  update(false, false, error);
329
- return $p.reject(error);
324
+ return Promise.reject(error);
330
325
  });
331
326
  };
332
327
 
@@ -336,8 +331,8 @@ module.exports = config => {
336
331
  // istanbul ignore next:
337
332
  // we keep 'npm.query' initialization here, even though it is always
338
333
  // pre-initialized by the 'database' module, for integrity purpose.
339
- npmLocal.query = npmLocal.query || npm.query(config);
340
- npmLocal.spex = npmLocal.spex || npm.spex(config.promiseLib);
334
+ npmLocal.query = npmLocal.query || npm.query();
335
+ npmLocal.spex = npmLocal.spex || npm.spex(Promise);
341
336
 
342
337
  return {
343
338
  Task, execute, callback
@@ -415,5 +410,4 @@ module.exports = config => {
415
410
  * Once the operation has finished, this property contains the result, depending on property `success`:
416
411
  * - data resolved by the operation, if `success = true`
417
412
  * - error / rejection reason, if `success = false`
418
- *
419
413
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-promise",
3
- "version": "11.14.0",
3
+ "version": "12.0.0",
4
4
  "description": "PostgreSQL interface for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "typings": "typescript/pg-promise.d.ts",
@@ -38,30 +38,29 @@
38
38
  },
39
39
  "license": "MIT",
40
40
  "engines": {
41
- "node": ">=14.0"
41
+ "node": ">=16.0"
42
42
  },
43
43
  "dependencies": {
44
44
  "assert-options": "0.8.3",
45
- "pg": "8.14.1",
46
- "pg-minify": "1.7.0",
45
+ "pg": "8.16.3",
46
+ "pg-minify": "1.8.0",
47
47
  "spex": "3.4.1"
48
48
  },
49
49
  "peerDependencies": {
50
- "pg-query-stream": "4.8.1"
50
+ "pg-query-stream": "4.10.3"
51
51
  },
52
52
  "devDependencies": {
53
- "@eslint/js": "9.28.0",
54
- "@types/node": "22.15.29",
55
- "bluebird": "3.7.2",
53
+ "@eslint/js": "9.34.0",
54
+ "@types/node": "24.3.0",
56
55
  "coveralls": "3.1.1",
57
- "cspell": "9.0.2",
58
- "eslint": "9.28.0",
59
- "globals": "16.2.0",
56
+ "cspell": "9.2.0",
57
+ "eslint": "9.34.0",
58
+ "globals": "16.3.0",
60
59
  "istanbul": "0.4.5",
61
60
  "jasmine-node": "3.0.0",
62
61
  "jsdoc": "4.0.4",
63
62
  "JSONStream": "1.3.5",
64
63
  "tslint": "6.1.3",
65
- "typescript": "5.8.3"
64
+ "typescript": "5.9.2"
66
65
  }
67
66
  }
@@ -21,7 +21,7 @@ const {value} = await db.one('SELECT 123 as value');
21
21
  #### With Extensions
22
22
 
23
23
  The library supports dynamic protocol extensions, via event [extend], which requires
24
- explicit extension interface to be declared and parameterized, as shown below.
24
+ an explicit extension interface to be declared and parameterized, as shown below.
25
25
 
26
26
  ```ts
27
27
  import * as pgPromise from 'pg-promise';
@@ -7,17 +7,6 @@
7
7
  * Removal or modification of this copyright notice is prohibited.
8
8
  */
9
9
 
10
- /////////////////////////////////////////
11
- // Requires pg-promise v11.0.0 or later.
12
- /////////////////////////////////////////
13
-
14
- // We use ES6 as static promise here, because generic promises are still not supported.
15
- // Follow the links below:
16
- // https://stackoverflow.com/questions/36593087/using-a-custom-promise-as-a-generic-type
17
- // https://github.com/Microsoft/TypeScript/issues/1213
18
-
19
- type XPromise<T> = Promise<T>;
20
-
21
10
  import * as pg from './pg-subset';
22
11
  import * as pgMinify from 'pg-minify';
23
12
  import * as spexLib from 'spex';
@@ -137,16 +126,6 @@ declare namespace pgPromise {
137
126
  table: string
138
127
  }
139
128
 
140
- interface IPromiseConfig {
141
- create(resolve: (value?: any) => void, reject?: (reason?: any) => void): XPromise<any>
142
-
143
- resolve(value?: any): void
144
-
145
- reject(reason?: any): void
146
-
147
- all(iterable: any): XPromise<any>
148
- }
149
-
150
129
  type FormattingFilter = '^' | '~' | '#' | ':raw' | ':alias' | ':name' | ':json' | ':csv' | ':list' | ':value';
151
130
 
152
131
  type QueryColumns<T> = Column<T> | ColumnSet<T> | Array<string | IColumnConfig<T> | Column<T>>;
@@ -292,12 +271,6 @@ declare namespace pgPromise {
292
271
  toString(level?: number): string
293
272
  }
294
273
 
295
- // PromiseAdapter class;
296
- // API: https://vitaly-t.github.io/pg-promise/PromiseAdapter.html
297
- class PromiseAdapter {
298
- constructor(api: IPromiseConfig)
299
- }
300
-
301
274
  const txMode: typeof _txMode;
302
275
  const utils: IUtils;
303
276
  const as: IFormatting;
@@ -308,7 +281,7 @@ declare namespace pgPromise {
308
281
  // We export this interface only to be able to help IntelliSense cast extension types correctly,
309
282
  // which doesn't always work, depending on the version of IntelliSense being used.
310
283
  interface IDatabase<Ext, C extends pg.IClient = pg.IClient> extends IBaseProtocol<Ext> {
311
- connect(options?: IConnectionOptions<C>): XPromise<IConnected<Ext, C>>
284
+ connect(options?: IConnectionOptions<C>): Promise<IConnected<Ext, C>>
312
285
 
313
286
  /////////////////////////////////////////////////////////////////////////////
314
287
  // Hidden, read-only properties, for integrating with third-party libraries:
@@ -331,7 +304,6 @@ declare namespace pgPromise {
331
304
  interface IMain<Ext = {}, C extends pg.IClient = pg.IClient> {
332
305
  <T = Ext, C extends pg.IClient = pg.IClient>(cn: string | pg.IConnectionParameters<C>, dc?: any): IDatabase<T, C> & T
333
306
 
334
- readonly PromiseAdapter: typeof PromiseAdapter
335
307
  readonly PreparedStatement: typeof PreparedStatement
336
308
  readonly ParameterizedQuery: typeof ParameterizedQuery
337
309
  readonly QueryFile: typeof QueryFile
@@ -369,89 +341,89 @@ declare namespace pgPromise {
369
341
  interface IBaseProtocol<Ext> {
370
342
 
371
343
  // API: https://vitaly-t.github.io/pg-promise/Database.html#query
372
- query<T = any>(query: QueryParam, values?: any, qrm?: queryResult): XPromise<T>
344
+ query<T = any>(query: QueryParam, values?: any, qrm?: queryResult): Promise<T>
373
345
 
374
346
  // result-specific methods;
375
347
 
376
348
  // API: https://vitaly-t.github.io/pg-promise/Database.html#none
377
- none(query: QueryParam, values?: any): XPromise<null>
349
+ none(query: QueryParam, values?: any): Promise<null>
378
350
 
379
351
  // API: https://vitaly-t.github.io/pg-promise/Database.html#one
380
- one<T = any>(query: QueryParam, values?: any, cb?: (value: any) => T, thisArg?: any): XPromise<T>
352
+ one<T = any>(query: QueryParam, values?: any, cb?: (value: any) => T, thisArg?: any): Promise<T>
381
353
 
382
354
  // API: https://vitaly-t.github.io/pg-promise/Database.html#oneOrNone
383
- oneOrNone<T = any>(query: QueryParam, values?: any, cb?: (value: any) => T, thisArg?: any): XPromise<T | null>
355
+ oneOrNone<T = any>(query: QueryParam, values?: any, cb?: (value: any) => T, thisArg?: any): Promise<T | null>
384
356
 
385
357
  // API: https://vitaly-t.github.io/pg-promise/Database.html#many
386
- many<T = any>(query: QueryParam, values?: any): XPromise<T[]>
358
+ many<T = any>(query: QueryParam, values?: any): Promise<T[]>
387
359
 
388
360
  // API: https://vitaly-t.github.io/pg-promise/Database.html#manyOrNone
389
- manyOrNone<T = any>(query: QueryParam, values?: any): XPromise<T[]>
361
+ manyOrNone<T = any>(query: QueryParam, values?: any): Promise<T[]>
390
362
 
391
363
  // API: https://vitaly-t.github.io/pg-promise/Database.html#any
392
- any<T = any>(query: QueryParam, values?: any): XPromise<T[]>
364
+ any<T = any>(query: QueryParam, values?: any): Promise<T[]>
393
365
 
394
366
  // API: https://vitaly-t.github.io/pg-promise/Database.html#result
395
- result<T, R = IResultExt<T>>(query: QueryParam, values?: any, cb?: (value: IResultExt<T>) => R, thisArg?: any): XPromise<R>
367
+ result<T, R = IResultExt<T>>(query: QueryParam, values?: any, cb?: (value: IResultExt<T>) => R, thisArg?: any): Promise<R>
396
368
 
397
369
  // API: https://vitaly-t.github.io/pg-promise/Database.html#multiResult
398
- multiResult(query: QueryParam, values?: any): XPromise<pg.IResult[]>
370
+ multiResult(query: QueryParam, values?: any): Promise<pg.IResult[]>
399
371
 
400
372
  // API: https://vitaly-t.github.io/pg-promise/Database.html#multi
401
- multi<T = any>(query: QueryParam, values?: any): XPromise<Array<T[]>>
373
+ multi<T = any>(query: QueryParam, values?: any): Promise<Array<T[]>>
402
374
 
403
375
  // API: https://vitaly-t.github.io/pg-promise/Database.html#stream
404
- stream(qs: NodeJS.ReadableStream, init: (stream: NodeJS.ReadableStream) => void): XPromise<{
376
+ stream(qs: NodeJS.ReadableStream, init: (stream: NodeJS.ReadableStream) => void): Promise<{
405
377
  processed: number,
406
378
  duration: number
407
379
  }>
408
380
 
409
381
  // API: https://vitaly-t.github.io/pg-promise/Database.html#func
410
- func<T = any>(funcName: string, values?: any, qrm?: queryResult): XPromise<T>
382
+ func<T = any>(funcName: string, values?: any, qrm?: queryResult): Promise<T>
411
383
 
412
384
  // API: https://vitaly-t.github.io/pg-promise/Database.html#proc
413
- proc<T = any>(procName: string, values?: any, cb?: (value: any) => T, thisArg?: any): XPromise<T | null>
385
+ proc<T = any>(procName: string, values?: any, cb?: (value: any) => T, thisArg?: any): Promise<T | null>
414
386
 
415
387
  // API: https://vitaly-t.github.io/pg-promise/Database.html#map
416
- map<T = any>(query: QueryParam, values: any, cb: (row: any, index: number, data: any[]) => T, thisArg?: any): XPromise<T[]>
388
+ map<T = any>(query: QueryParam, values: any, cb: (row: any, index: number, data: any[]) => T, thisArg?: any): Promise<T[]>
417
389
 
418
390
  // API: https://vitaly-t.github.io/pg-promise/Database.html#each
419
- each<T = any>(query: QueryParam, values: any, cb: (row: any, index: number, data: any[]) => void, thisArg?: any): XPromise<T[]>
391
+ each<T = any>(query: QueryParam, values: any, cb: (row: any, index: number, data: any[]) => void, thisArg?: any): Promise<T[]>
420
392
 
421
393
  // Tasks;
422
394
  // API: https://vitaly-t.github.io/pg-promise/Database.html#task
423
- task<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
395
+ task<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
424
396
 
425
- task<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
397
+ task<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
426
398
 
427
- task<T>(options: { tag?: any }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
399
+ task<T>(options: { tag?: any }, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
428
400
 
429
401
  // Conditional Tasks;
430
402
  // API: https://vitaly-t.github.io/pg-promise/Database.html#taskIf
431
- taskIf<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
403
+ taskIf<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
432
404
 
433
- taskIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
405
+ taskIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
434
406
 
435
- taskIf<T>(options: ITaskIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
407
+ taskIf<T>(options: ITaskIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
436
408
 
437
409
  // Transactions;
438
410
  // API: https://vitaly-t.github.io/pg-promise/Database.html#tx
439
- tx<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
411
+ tx<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
440
412
 
441
- tx<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
413
+ tx<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
442
414
 
443
415
  tx<T>(options: {
444
416
  tag?: any,
445
417
  mode?: _txMode.TransactionMode | null
446
- }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
418
+ }, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
447
419
 
448
420
  // Conditional Transactions;
449
421
  // API: https://vitaly-t.github.io/pg-promise/Database.html#txIf
450
- txIf<T>(cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
422
+ txIf<T>(cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
451
423
 
452
- txIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
424
+ txIf<T>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
453
425
 
454
- txIf<T>(options: ITxIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
426
+ txIf<T>(options: ITxIfOptions<Ext>, cb: (t: ITask<Ext> & Ext) => T | Promise<T>): Promise<T>
455
427
  }
456
428
 
457
429
  // Database object in connected state;
@@ -465,17 +437,17 @@ declare namespace pgPromise {
465
437
 
466
438
  // But for direct connections (connect({direct: true})), `kill` flag is ignored, because
467
439
  // the connection is always closed physically, which may take time, and so in this case
468
- // the method returns a Promise, to indicate when the connection finished closing.
469
- done(kill?: boolean): void | XPromise<void>;
440
+ // the method returns a Promise to indicate when the connection finished closing.
441
+ done(kill?: boolean): void | Promise<void>;
470
442
 
471
- // Repeated calls are not allowed, and will throw an error.
443
+ // Repeated calls are not allowed and will throw an error.
472
444
  }
473
445
 
474
446
  // Event context extension for tasks + transactions;
475
447
  // See: https://vitaly-t.github.io/pg-promise/global.html#TaskContext
476
448
  interface ITaskContext {
477
449
 
478
- // these are set in the beginning of each task/transaction:
450
+ // these are set at the beginning of each task/transaction:
479
451
  readonly context: any
480
452
  readonly parent: ITaskContext | null
481
453
  readonly connected: boolean
@@ -510,7 +482,7 @@ declare namespace pgPromise {
510
482
  query: any
511
483
  params: any,
512
484
  values: any,
513
- queryFilePath?: string,
485
+ queryFilePath?: string,
514
486
  ctx: ITaskContext
515
487
  }
516
488
 
@@ -599,7 +571,6 @@ declare namespace pgPromise {
599
571
  noWarnings?: boolean
600
572
  pgFormatting?: boolean
601
573
  pgNative?: boolean
602
- promiseLib?: any
603
574
  capSQL?: boolean
604
575
  schema?: ValidSchema | ((dc: any) => ValidSchema)
605
576
 
@@ -609,7 +580,7 @@ declare namespace pgPromise {
609
580
 
610
581
  query?(e: IEventContext<C>): void
611
582
 
612
- // NOTE: result is undefined when data comes from QueryStream, i.e. via method Database.stream
583
+ // NOTE: The result is undefined when data comes from QueryStream, i.e. via method Database.stream
613
584
  receive?(e: { data: any[], result: IResultExt | void, ctx: IEventContext<C> }): void
614
585
 
615
586
  task?(e: IEventContext<C>): void
@@ -624,7 +595,6 @@ declare namespace pgPromise {
624
595
  // API: https://vitaly-t.github.io/pg-promise/Database.html#$config
625
596
  interface ILibConfig<Ext, C extends pg.IClient = pg.IClient> {
626
597
  version: string
627
- promiseLib: any
628
598
  promise: IGenericPromise
629
599
  options: IInitOptions<Ext, C>
630
600
  pgp: IMain<Ext, C>
@@ -723,13 +693,13 @@ declare namespace pgPromise {
723
693
  }
724
694
 
725
695
  interface IGenericPromise {
726
- (cb: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void): XPromise<any>
696
+ (cb: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void): Promise<any>
727
697
 
728
698
  resolve(value?: any): void
729
699
 
730
700
  reject(reason?: any): void
731
701
 
732
- all(iterable: any): XPromise<any>
702
+ all(iterable: any): Promise<any>
733
703
  }
734
704
  }
735
705
 
@@ -30,7 +30,7 @@ declare namespace pg {
30
30
  oid: number
31
31
  dataTypeID: number
32
32
 
33
- // NOTE: properties below are not available within Native Bindings:
33
+ // NOTE: The properties below are not available within Native Bindings:
34
34
 
35
35
  tableID: number
36
36
  columnID: number
@@ -1,86 +0,0 @@
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
- const {assert} = require('./assert');
11
-
12
- /**
13
- * @class PromiseAdapter
14
- * @summary Adapter for the primary promise operations.
15
- * @description
16
- * Provides compatibility with promise libraries that cannot be recognized automatically,
17
- * via functions that implement the primary operations with promises:
18
- *
19
- * - construct a new promise with a callback function
20
- * - resolve a promise with some result data
21
- * - reject a promise with a reason
22
- * - resolve an array of promises
23
- *
24
- * The type is available from the library's root: `pgp.PromiseAdapter`.
25
- *
26
- * @param {object} api
27
- * Promise API configuration object.
28
- *
29
- * Passing in anything other than an object will throw {@link external:TypeError TypeError} = `Adapter requires an api configuration object.`
30
- *
31
- * @param {function} api.create
32
- * A function that takes a callback parameter and returns a new promise object.
33
- * The callback parameter is expected to be `function(resolve, reject)`.
34
- *
35
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'create' must be specified.`
36
- *
37
- * @param {function} api.resolve
38
- * A function that takes an optional data parameter and resolves a promise with it.
39
- *
40
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'resolve' must be specified.`
41
- *
42
- * @param {function} api.reject
43
- * A function that takes an optional error parameter and rejects a promise with it.
44
- *
45
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'reject' must be specified.`
46
- *
47
- * @param {function} api.all
48
- * A function that resolves an array of promises.
49
- *
50
- * Passing in anything other than a function will throw {@link external:TypeError TypeError} = `Function 'all' must be specified.`
51
- *
52
- * @returns {PromiseAdapter}
53
- */
54
- class PromiseAdapter {
55
- constructor(api) {
56
-
57
- if (!api || typeof api !== 'object') {
58
- throw new TypeError('Adapter requires an api configuration object.');
59
- }
60
-
61
- api = assert(api, ['create', 'resolve', 'reject', 'all']);
62
-
63
- this.create = api.create;
64
- this.resolve = api.resolve;
65
- this.reject = api.reject;
66
- this.all = api.all;
67
-
68
- if (typeof this.create !== 'function') {
69
- throw new TypeError('Function \'create\' must be specified.');
70
- }
71
-
72
- if (typeof this.resolve !== 'function') {
73
- throw new TypeError('Function \'resolve\' must be specified.');
74
- }
75
-
76
- if (typeof this.reject !== 'function') {
77
- throw new TypeError('Function \'reject\' must be specified.');
78
- }
79
-
80
- if (typeof this.all !== 'function') {
81
- throw new TypeError('Function \'all\' must be specified.');
82
- }
83
- }
84
- }
85
-
86
- module.exports = {PromiseAdapter};
@@ -1,56 +0,0 @@
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
- const {PromiseAdapter} = require('./promise-adapter');
11
-
12
- //////////////////////////////////////////
13
- // Parses and validates a promise library;
14
- function parse(pl) {
15
-
16
- let promise;
17
- if (pl instanceof PromiseAdapter) {
18
- promise = function (func) {
19
- return pl.create(func);
20
- };
21
- promise.resolve = pl.resolve;
22
- promise.reject = pl.reject;
23
- promise.all = pl.all;
24
- return promise;
25
- }
26
- const t = typeof pl;
27
- if (t === 'function' || t === 'object') {
28
- const Root = typeof pl.Promise === 'function' ? pl.Promise : pl;
29
- promise = function (func) {
30
- return new Root(func);
31
- };
32
- promise.resolve = Root.resolve;
33
- promise.reject = Root.reject;
34
- promise.all = Root.all;
35
- if (typeof promise.resolve === 'function' &&
36
- typeof promise.reject === 'function' &&
37
- typeof promise.all === 'function') {
38
- return promise;
39
- }
40
- }
41
-
42
- throw new TypeError('Invalid promise library specified.');
43
- }
44
-
45
- function parsePromise(promiseLib) {
46
- const result = {promiseLib};
47
- if (promiseLib) {
48
- result.promise = parse(promiseLib);
49
- } else {
50
- result.promise = parse(Promise);
51
- result.promiseLib = Promise;
52
- }
53
- return result;
54
- }
55
-
56
- module.exports = {parsePromise};