From 8802545e61f161feb729edf4d1d69967f96126d7 Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Sat, 25 May 2024 15:03:04 +0100 Subject: [PATCH] refactoring TypeScript for _TN function --- lib/helpers/table-name.js | 7 ++++--- package.json | 2 +- typescript/pg-promise.d.ts | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/helpers/table-name.js b/lib/helpers/table-name.js index 2e9528f3..4ad74da3 100644 --- a/lib/helpers/table-name.js +++ b/lib/helpers/table-name.js @@ -140,7 +140,7 @@ npm.utils.addInspection(TableName, function () { * @function helpers._TN * @description * Table-Name helper function, to convert any `"schema.table"` string - * into `{schema, table}` object. + * into `{schema, table}` object. It also works as a template-tag function. * * @example * const {ColumnSet, _TN} = pgp.helpers; @@ -149,14 +149,15 @@ npm.utils.addInspection(TableName, function () { * const cs1 = new ColumnSet(['id', 'name'], {table: _TN('schema.table')}); * * // Using as a template-tag function: - * const cs2 = new ColumnSet(['id', 'name'], {table: _TN`schema.table`}); + * const schema = 'schema'; + * const cs2 = new ColumnSet(['id', 'name'], {table: _TN`${schema}.table`}); * * @returns {Table} */ function _TN(a, ...args) { if (Array.isArray(a) && a.raw) { a = a.map((b, i) => b + (i < args.length ? args[i] : '')).join(''); - } + } // else 'a' is a string const [schema, table] = a.split('.'); return table === undefined ? {table: schema} : {schema, table}; } diff --git a/package.json b/package.json index 45d17ae0..1e126be1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pg-promise", - "version": "11.7.4", + "version": "11.7.5", "description": "PostgreSQL interface for Node.js", "main": "lib/index.js", "typings": "typescript/pg-promise.d.ts", diff --git a/typescript/pg-promise.d.ts b/typescript/pg-promise.d.ts index 3365a109..34cd3ba3 100644 --- a/typescript/pg-promise.d.ts +++ b/typescript/pg-promise.d.ts @@ -708,7 +708,8 @@ declare namespace pgPromise { ColumnSet: typeof ColumnSet TableName: typeof TableName - _TN: (data: TemplateStringsArray | string, ...args: Array) => ITable + _TN(data: TemplateStringsArray, ...args: Array): ITable + _TN(s: string) :ITable } interface IGenericPromise {