pg-promise 11.5.5 → 11.7.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,8 +2,8 @@ pg-promise
2
2
  ==========
3
3
 
4
4
  [![Build Status](https://github.com/vitaly-t/pg-promise/workflows/ci/badge.svg?branch=master)](https://github.com/vitaly-t/pg-promise/actions?query=workflow%3Aci+branch%3Amaster)
5
- [![Node Version](https://img.shields.io/badge/nodejs-14%20--%2018-green.svg?logo=node.js&style=flat)](https://nodejs.org)
6
- [![Postgres Version](https://img.shields.io/badge/postgresql-10%20--%2015-green.svg?logo=postgresql&style=flat)](https://www.postgresql.org)
5
+ [![Node Version](https://img.shields.io/badge/nodejs-14%20--%2020-green.svg?logo=node.js&style=flat)](https://nodejs.org)
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
  ---
9
9
 
package/lib/formatting.js CHANGED
@@ -170,7 +170,7 @@ const formatAs = {
170
170
  array({query, array, raw, options}) {
171
171
  options = options && typeof options === 'object' ? options : {};
172
172
  return query.replace(npm.patterns.multipleValues, name => {
173
- const v = formatAs.stripName(name.substr(1), raw);
173
+ const v = formatAs.stripName(name.substring(1), raw);
174
174
  const idx = v.name - 1;
175
175
  if (idx >= maxVariable) {
176
176
  throw new RangeError(`Variable $${v.name} exceeds supported maximum of $${maxVariable}`);
@@ -200,7 +200,7 @@ const formatAs = {
200
200
  const mod = name.match(npm.patterns.hasValidModifier);
201
201
  if (mod) {
202
202
  return {
203
- name: name.substr(0, mod.index),
203
+ name: name.substring(0, mod.index),
204
204
  fm: fmMap[mod[0]] | (raw ? fmFlags.raw : 0)
205
205
  };
206
206
  }
@@ -266,11 +266,11 @@ function parseColumn(name) {
266
266
  const res = {};
267
267
  if (name[0] === '?') {
268
268
  res.cnd = true;
269
- name = name.substr(1);
269
+ name = name.substring(1);
270
270
  }
271
271
  const mod = name.match(npm.patterns.hasValidModifier);
272
272
  if (mod) {
273
- res.name = name.substr(0, mod.index);
273
+ res.name = name.substring(0, mod.index);
274
274
  res.mod = mod[0];
275
275
  } else {
276
276
  res.name = name;
@@ -9,7 +9,7 @@
9
9
 
10
10
  const {Column} = require('./column');
11
11
  const {ColumnSet} = require('./column-set');
12
- const {TableName} = require('./table-name');
12
+ const {TableName, _TN} = require('./table-name');
13
13
  const method = require('./methods');
14
14
 
15
15
  /**
@@ -24,6 +24,9 @@ const method = require('./methods');
24
24
  * @property {function} TableName
25
25
  * {@link helpers.TableName TableName} class constructor.
26
26
  *
27
+ * @property {function} _TN
28
+ * {@link helpers._TN _TN} Table-Name template tag function.
29
+ *
27
30
  * @property {function} ColumnSet
28
31
  * {@link helpers.ColumnSet ColumnSet} class constructor.
29
32
  *
@@ -64,6 +67,7 @@ module.exports = config => {
64
67
  return method.sets(data, columns, capSQL());
65
68
  },
66
69
  TableName,
70
+ _TN,
67
71
  ColumnSet,
68
72
  Column
69
73
  };
@@ -46,6 +46,7 @@ const npm = {
46
46
  * @returns {helpers.TableName}
47
47
  *
48
48
  * @see
49
+ * {@link helpers._TN _TN},
49
50
  * {@link helpers.TableName#toPostgres toPostgres}
50
51
  *
51
52
  * @example
@@ -125,4 +126,32 @@ npm.utils.addInspection(TableName, function () {
125
126
  return this.toString();
126
127
  });
127
128
 
128
- module.exports = {TableName};
129
+ /**
130
+ *
131
+ * @interface Table
132
+ * @description
133
+ * Structure for any table name/path.
134
+ *
135
+ * @property {string} [schema] - schema name, if specified
136
+ * @property {string} table - table name
137
+ */
138
+
139
+ /**
140
+ * @function helpers._TN
141
+ * @description
142
+ * Table-Name template tag function, to convert any `"schema.table"` string
143
+ * into `{schema, table}` object.
144
+ *
145
+ * @example
146
+ * const {ColumnSet, _TN} = pgp.helpers;
147
+ *
148
+ * const cs = new ColumnSet(['id', 'name'], {table: _TN`schema.table`});
149
+ *
150
+ * @returns {Table}
151
+ */
152
+ function _TN(data) {
153
+ const [schema, table] = data[0].split('.');
154
+ return table === undefined ? {table: schema} : {schema, table};
155
+ }
156
+
157
+ module.exports = {TableName, _TN};
package/lib/main.js CHANGED
@@ -36,7 +36,7 @@ let originalClientConnect;
36
36
  * @module pg-promise
37
37
  *
38
38
  * @description
39
- * ## pg-promise v11.4
39
+ * ## pg-promise v11.7
40
40
  * All documentation here is for the latest official release only.
41
41
  *
42
42
  * ### Initialization Options
@@ -162,7 +162,7 @@ function addInspection(type, cb) {
162
162
  // This is for detecting when to skip executing ROLLBACK for a failed transaction.
163
163
  function isConnectivityError(err) {
164
164
  const code = err && typeof err.code === 'string' && err.code;
165
- const cls = code && code.substr(0, 2); // Error Class
165
+ const cls = code && code.substring(0, 2); // Error Class
166
166
  // istanbul ignore next (we cannot test-cover all error cases):
167
167
  return code === 'ECONNRESET' || (cls === '08' && code !== '08P01') || (cls === '57' && code !== '57014');
168
168
  // Code 'ECONNRESET' - Connectivity issue handled by the driver.
@@ -39,7 +39,7 @@ const npm = {
39
39
  */
40
40
  function camelize(text) {
41
41
  text = text.replace(/[-_\s.]+(.)?/g, (_, c) => c ? c.toUpperCase() : '');
42
- return text.substr(0, 1).toLowerCase() + text.substr(1);
42
+ return text.substring(0, 1).toLowerCase() + text.substring(1);
43
43
  }
44
44
 
45
45
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-promise",
3
- "version": "11.5.5",
3
+ "version": "11.7.0",
4
4
  "description": "PostgreSQL interface for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "typings": "typescript/pg-promise.d.ts",
@@ -42,22 +42,24 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "assert-options": "0.8.1",
45
- "pg": "8.11.3",
46
- "pg-minify": "1.6.3",
45
+ "pg": "8.11.5",
46
+ "pg-minify": "1.6.4",
47
47
  "spex": "3.3.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@types/node": "20.5.2",
50
+ "@eslint/js": "9.3.0",
51
+ "@types/node": "20.12.12",
51
52
  "bluebird": "3.7.2",
52
53
  "coveralls": "3.1.1",
53
- "cspell": "8.6.0",
54
- "eslint": "8.57.0",
54
+ "cspell": "8.8.3",
55
+ "eslint": "9.3.0",
56
+ "globals": "15.3.0",
55
57
  "istanbul": "0.4.5",
56
58
  "jasmine-node": "3.0.0",
57
- "jsdoc": "4.0.2",
59
+ "jsdoc": "4.0.3",
58
60
  "JSONStream": "1.3.5",
59
- "pg-query-stream": "4.5.3",
61
+ "pg-query-stream": "4.5.5",
60
62
  "tslint": "6.1.3",
61
- "typescript": "5.4.3"
63
+ "typescript": "5.4.5"
62
64
  }
63
65
  }
@@ -130,8 +130,8 @@ declare namespace pgPromise {
130
130
  }
131
131
 
132
132
  interface ITable {
133
- table: string
134
133
  schema?: string
134
+ table: string
135
135
  }
136
136
 
137
137
  interface IPromiseConfig {
@@ -207,7 +207,11 @@ declare namespace pgPromise {
207
207
 
208
208
  assign(source?: { source?: object, prefix?: string }): string
209
209
 
210
- assignColumns(options?: { from?: string, to?: string, skip?: string | string[] | ((c: Column<T>) => boolean) }): string
210
+ assignColumns(options?: {
211
+ from?: string,
212
+ to?: string,
213
+ skip?: string | string[] | ((c: Column<T>) => boolean)
214
+ }): string
211
215
 
212
216
  extend<S>(columns: Column<T> | ColumnSet<T> | Array<string | IColumnConfig<T> | Column<T>>): ColumnSet<S>
213
217
 
@@ -382,7 +386,10 @@ declare namespace pgPromise {
382
386
  multi<T = any>(query: QueryParam, values?: any): XPromise<Array<T[]>>
383
387
 
384
388
  // API: https://vitaly-t.github.io/pg-promise/Database.html#stream
385
- stream(qs: NodeJS.ReadableStream, init: (stream: NodeJS.ReadableStream) => void): XPromise<{ processed: number, duration: number }>
389
+ stream(qs: NodeJS.ReadableStream, init: (stream: NodeJS.ReadableStream) => void): XPromise<{
390
+ processed: number,
391
+ duration: number
392
+ }>
386
393
 
387
394
  // API: https://vitaly-t.github.io/pg-promise/Database.html#func
388
395
  func<T = any>(funcName: string, values?: any, qrm?: queryResult): XPromise<T>
@@ -410,7 +417,10 @@ declare namespace pgPromise {
410
417
 
411
418
  taskIf<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
412
419
 
413
- taskIf<T = any>(options: { tag?: any, cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean) }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
420
+ taskIf<T = any>(options: {
421
+ tag?: any,
422
+ cnd?: boolean | ((t: ITask<Ext> & Ext) => boolean)
423
+ }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
414
424
 
415
425
  // Transactions;
416
426
  // API: https://vitaly-t.github.io/pg-promise/Database.html#tx
@@ -418,7 +428,10 @@ declare namespace pgPromise {
418
428
 
419
429
  tx<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
420
430
 
421
- tx<T = any>(options: { tag?: any, mode?: _txMode.TransactionMode | null }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
431
+ tx<T = any>(options: {
432
+ tag?: any,
433
+ mode?: _txMode.TransactionMode | null
434
+ }, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
422
435
 
423
436
  // Conditional Transactions;
424
437
  // API: https://vitaly-t.github.io/pg-promise/Database.html#txIf
@@ -426,7 +439,12 @@ declare namespace pgPromise {
426
439
 
427
440
  txIf<T = any>(tag: string | number, cb: (t: ITask<Ext> & Ext) => T | XPromise<T>): XPromise<T>
428
441
 
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>
442
+ txIf<T = any>(options: {
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>
430
448
  }
431
449
 
432
450
  // Database object in connected state;
@@ -656,7 +674,10 @@ declare namespace pgPromise {
656
674
 
657
675
  camelizeVar(text: string): string
658
676
 
659
- enumSql(dir: string, options?: { recursive?: boolean, ignoreErrors?: boolean }, cb?: (file: string, name: string, path: string) => any): any
677
+ enumSql(dir: string, options?: {
678
+ recursive?: boolean,
679
+ ignoreErrors?: boolean
680
+ }, cb?: (file: string, name: string, path: string) => any): any
660
681
 
661
682
  taskArgs<T = {}>(args: IArguments): ITaskArguments<T>
662
683
  }
@@ -665,11 +686,19 @@ declare namespace pgPromise {
665
686
  // API: https://vitaly-t.github.io/pg-promise/helpers.html
666
687
  interface IHelpers {
667
688
 
668
- concat(queries: Array<string | QueryFile | { query: string | QueryFile, values?: any, options?: IFormattingOptions }>): string
689
+ concat(queries: Array<string | QueryFile | {
690
+ query: string | QueryFile,
691
+ values?: any,
692
+ options?: IFormattingOptions
693
+ }>): string
669
694
 
670
695
  insert(data: object | object[], columns?: QueryColumns<any> | null, table?: string | ITable | TableName): string
671
696
 
672
- update(data: object | object[], columns?: QueryColumns<any> | null, table?: string | ITable | TableName, options?: { tableAlias?: string, valueAlias?: string, emptyUpdate?: any }): any
697
+ update(data: object | object[], columns?: QueryColumns<any> | null, table?: string | ITable | TableName, options?: {
698
+ tableAlias?: string,
699
+ valueAlias?: string,
700
+ emptyUpdate?: any
701
+ }): any
673
702
 
674
703
  values(data: object | object[], columns?: QueryColumns<any> | null): string
675
704
 
@@ -678,6 +707,8 @@ declare namespace pgPromise {
678
707
  Column: typeof Column
679
708
  ColumnSet: typeof ColumnSet
680
709
  TableName: typeof TableName
710
+
711
+ _TN: (data: TemplateStringsArray) => ITable
681
712
  }
682
713
 
683
714
  interface IGenericPromise {