Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed May 26, 2024
1 parent b9ae52a commit f6a8abc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 14 additions & 7 deletions lib/helpers/table-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ npm.utils.addInspection(TableName, function () {
});

/**
*
* @interface Table
* @description
* Structure for any table name/path.
Expand All @@ -140,12 +139,20 @@ npm.utils.addInspection(TableName, function () {
* @see {@link helpers.TableName TableName}, {@link helpers._TN _TN}
*/

/**
* @external TemplateStringsArray
* @see https://microsoft.github.io/PowerBI-JavaScript/interfaces/_node_modules_typedoc_node_modules_typescript_lib_lib_es5_d_.templatestringsarray.html
*/

/**
* @function helpers._TN
* @description
* Table-Name helper function, to convert any `"schema.table"` string
* into `{schema, table}` object. It also works as a template-tag function.
*
* @param {string|TemplateStringsArray} path
* Table-name path, as a simple string or a template string (with parameters).
*
* @example
* const {ColumnSet, _TN} = pgp.helpers;
*
Expand All @@ -158,13 +165,13 @@ npm.utils.addInspection(TableName, function () {
*
* @returns {Table}
*
* @see {@link helpers.TableName TableName}
* @see {@link helpers.TableName TableName}, {@link external:TemplateStringsArray TemplateStringsArray}
*/
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('.');
function _TN(path, ...args) {
if (Array.isArray(path) && path.raw) {
path = path.map((b, i) => b + (i < args.length ? args[i] ?? '' : '')).join('');
} // else 'path' is a string
const [schema, table] = path.split('.');
if (table === undefined) {
return {table: schema};
}
Expand Down
4 changes: 2 additions & 2 deletions typescript/pg-promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ declare namespace pgPromise {
ColumnSet: typeof ColumnSet
TableName: typeof TableName

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

interface IGenericPromise {
Expand Down

0 comments on commit f6a8abc

Please sign in to comment.