pg-promise 11.7.4 → 11.7.6

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.
@@ -140,7 +140,7 @@ npm.utils.addInspection(TableName, function () {
140
140
  * @function helpers._TN
141
141
  * @description
142
142
  * Table-Name helper function, to convert any `"schema.table"` string
143
- * into `{schema, table}` object.
143
+ * into `{schema, table}` object. It also works as a template-tag function.
144
144
  *
145
145
  * @example
146
146
  * const {ColumnSet, _TN} = pgp.helpers;
@@ -149,16 +149,20 @@ npm.utils.addInspection(TableName, function () {
149
149
  * const cs1 = new ColumnSet(['id', 'name'], {table: _TN('schema.table')});
150
150
  *
151
151
  * // Using as a template-tag function:
152
- * const cs2 = new ColumnSet(['id', 'name'], {table: _TN`schema.table`});
152
+ * const schema = 'schema';
153
+ * const cs2 = new ColumnSet(['id', 'name'], {table: _TN`${schema}.table`});
153
154
  *
154
155
  * @returns {Table}
155
156
  */
156
157
  function _TN(a, ...args) {
157
158
  if (Array.isArray(a) && a.raw) {
158
159
  a = a.map((b, i) => b + (i < args.length ? args[i] : '')).join('');
159
- }
160
+ } // else 'a' is a string
160
161
  const [schema, table] = a.split('.');
161
- return table === undefined ? {table: schema} : {schema, table};
162
+ if(table === undefined) {
163
+ return {table: schema};
164
+ }
165
+ return schema ? {schema, table} : {table};
162
166
  }
163
167
 
164
168
  module.exports = {TableName, _TN};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pg-promise",
3
- "version": "11.7.4",
3
+ "version": "11.7.6",
4
4
  "description": "PostgreSQL interface for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "typings": "typescript/pg-promise.d.ts",
@@ -708,7 +708,8 @@ declare namespace pgPromise {
708
708
  ColumnSet: typeof ColumnSet
709
709
  TableName: typeof TableName
710
710
 
711
- _TN: (data: TemplateStringsArray | string, ...args: Array<any>) => ITable
711
+ _TN(data: TemplateStringsArray, ...args: Array<any>): ITable
712
+ _TN(s: string) :ITable
712
713
  }
713
714
 
714
715
  interface IGenericPromise {