Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improving _TN function #933

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading