Skip to content

Commit

Permalink
improving _TN function (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed May 25, 2024
1 parent 768e6ee commit 057b09b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const method = require('./methods');
* {@link helpers.TableName TableName} class constructor.
*
* @property {function} _TN
* {@link helpers._TN _TN} Table-Name template tag function.
* {@link helpers._TN _TN} Table-Name conversion function.
*
* @property {function} ColumnSet
* {@link helpers.ColumnSet ColumnSet} class constructor.
Expand Down
12 changes: 8 additions & 4 deletions lib/helpers/table-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,22 @@ npm.utils.addInspection(TableName, function () {
/**
* @function helpers._TN
* @description
* Table-Name template tag function, to convert any `"schema.table"` string
* Table-Name helper function, to convert any `"schema.table"` string
* into `{schema, table}` object.
*
* @example
* const {ColumnSet, _TN} = pgp.helpers;
*
* const cs = new ColumnSet(['id', 'name'], {table: _TN`schema.table`});
* // Using as a regular 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`});
*
* @returns {Table}
*/
function _TN(data) {
const [schema, table] = data[0].split('.');
function _TN(s) {
const [schema, table] = (s.raw ? s[0] : s).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.0",
"version": "11.7.1",
"description": "PostgreSQL interface for Node.js",
"main": "lib/index.js",
"typings": "typescript/pg-promise.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion typescript/pg-promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ declare namespace pgPromise {
ColumnSet: typeof ColumnSet
TableName: typeof TableName

_TN: (data: TemplateStringsArray) => ITable
_TN: (data: TemplateStringsArray | string) => ITable
}

interface IGenericPromise {
Expand Down

0 comments on commit 057b09b

Please sign in to comment.