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

adding _TN function #932

Merged
merged 2 commits 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
6 changes: 5 additions & 1 deletion lib/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const {Column} = require('./column');
const {ColumnSet} = require('./column-set');
const {TableName} = require('./table-name');
const {TableName, _TN} = require('./table-name');
const method = require('./methods');

/**
Expand All @@ -24,6 +24,9 @@ const method = require('./methods');
* @property {function} TableName
* {@link helpers.TableName TableName} class constructor.
*
* @property {function} _TN
* {@link helpers._TN _TN} Table-Name template tag function.
*
* @property {function} ColumnSet
* {@link helpers.ColumnSet ColumnSet} class constructor.
*
Expand Down Expand Up @@ -64,6 +67,7 @@ module.exports = config => {
return method.sets(data, columns, capSQL());
},
TableName,
_TN,
ColumnSet,
Column
};
Expand Down
31 changes: 30 additions & 1 deletion lib/helpers/table-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const npm = {
* @returns {helpers.TableName}
*
* @see
* {@link helpers._TN _TN},
* {@link helpers.TableName#toPostgres toPostgres}
*
* @example
Expand Down Expand Up @@ -125,4 +126,32 @@ npm.utils.addInspection(TableName, function () {
return this.toString();
});

module.exports = {TableName};
/**
*
* @interface Table
* @description
* Structure for any table name/path.
*
* @property {string} [schema] - schema name, if specified
* @property {string} table - table name
*/

/**
* @function helpers._TN
* @description
* Table-Name template tag 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`});
*
* @returns {Table}
*/
function _TN(data) {
const [schema, table] = data[0].split('.');
return table === undefined ? {table: schema} : {schema, table};
}

module.exports = {TableName, _TN};
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
"spex": "3.3.0"
},
"devDependencies": {
"@eslint/js": "9.1.1",
"@types/node": "20.12.7",
"@eslint/js": "9.3.0",
"@types/node": "20.12.12",
"bluebird": "3.7.2",
"coveralls": "3.1.1",
"cspell": "8.7.0",
"eslint": "9.1.0",
"globals": "15.0.0",
"cspell": "8.8.3",
"eslint": "9.3.0",
"globals": "15.3.0",
"istanbul": "0.4.5",
"jasmine-node": "3.0.0",
"jsdoc": "4.0.2",
"jsdoc": "4.0.3",
"JSONStream": "1.3.5",
"pg-query-stream": "4.5.5",
"tslint": "6.1.3",
Expand Down
Loading
Loading