Skip to content

Commit

Permalink
refactoring TypeScript for _TN function
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed May 25, 2024
1 parent 464e844 commit 8802545
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions lib/helpers/table-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion typescript/pg-promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ declare namespace pgPromise {
ColumnSet: typeof ColumnSet
TableName: typeof TableName

_TN: (data: TemplateStringsArray | string, ...args: Array<any>) => ITable
_TN(data: TemplateStringsArray, ...args: Array<any>): ITable
_TN(s: string) :ITable
}

interface IGenericPromise {
Expand Down

0 comments on commit 8802545

Please sign in to comment.