pg-promise 11.7.0 → 11.7.2
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/helpers/index.js
CHANGED
|
@@ -25,7 +25,7 @@ const method = require('./methods');
|
|
|
25
25
|
* {@link helpers.TableName TableName} class constructor.
|
|
26
26
|
*
|
|
27
27
|
* @property {function} _TN
|
|
28
|
-
* {@link helpers._TN _TN} Table-Name
|
|
28
|
+
* {@link helpers._TN _TN} Table-Name conversion function.
|
|
29
29
|
*
|
|
30
30
|
* @property {function} ColumnSet
|
|
31
31
|
* {@link helpers.ColumnSet ColumnSet} class constructor.
|
|
@@ -139,18 +139,25 @@ npm.utils.addInspection(TableName, function () {
|
|
|
139
139
|
/**
|
|
140
140
|
* @function helpers._TN
|
|
141
141
|
* @description
|
|
142
|
-
* Table-Name
|
|
142
|
+
* Table-Name helper function, to convert any `"schema.table"` string
|
|
143
143
|
* into `{schema, table}` object.
|
|
144
144
|
*
|
|
145
145
|
* @example
|
|
146
146
|
* const {ColumnSet, _TN} = pgp.helpers;
|
|
147
147
|
*
|
|
148
|
-
*
|
|
148
|
+
* // Using as a regular function:
|
|
149
|
+
* const cs1 = new ColumnSet(['id', 'name'], {table: _TN('schema.table')});
|
|
150
|
+
*
|
|
151
|
+
* // Using as a template-tag function:
|
|
152
|
+
* const cs2 = new ColumnSet(['id', 'name'], {table: _TN`schema.table`});
|
|
149
153
|
*
|
|
150
154
|
* @returns {Table}
|
|
151
155
|
*/
|
|
152
|
-
function _TN(
|
|
153
|
-
|
|
156
|
+
function _TN(a, ...args) {
|
|
157
|
+
if (Array.isArray(a) && a.raw) {
|
|
158
|
+
a = args.length ? args.map((b, i) => a[i] + b).join('') : a[0];
|
|
159
|
+
}
|
|
160
|
+
const [schema, table] = a.split('.');
|
|
154
161
|
return table === undefined ? {table: schema} : {schema, table};
|
|
155
162
|
}
|
|
156
163
|
|
package/package.json
CHANGED
|
@@ -708,7 +708,7 @@ declare namespace pgPromise {
|
|
|
708
708
|
ColumnSet: typeof ColumnSet
|
|
709
709
|
TableName: typeof TableName
|
|
710
710
|
|
|
711
|
-
_TN: (data: TemplateStringsArray) => ITable
|
|
711
|
+
_TN: (data: TemplateStringsArray | string, ...args: Array<any>) => ITable
|
|
712
712
|
}
|
|
713
713
|
|
|
714
714
|
interface IGenericPromise {
|