Skip to content

Commit

Permalink
fixing null|undefined 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 19776db commit bf10682
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/helpers/table-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ npm.utils.addInspection(TableName, function () {
*/
function _TN(a, ...args) {
if (Array.isArray(a) && a.raw) {
a = a.map((b, i) => b + (i < args.length ? args[i] : '')).join('');
a = a.map((b, i) => b + (i < args.length ? args[i] ?? '' : '')).join('');
} // else 'a' is a string
const [schema, table] = a.split('.');
if(table === undefined) {
if (table === undefined) {
return {table: schema};
}
return schema ? {schema, table} : {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.6",
"version": "11.7.7",
"description": "PostgreSQL interface for Node.js",
"main": "lib/index.js",
"typings": "typescript/pg-promise.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions test/help.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,5 +982,17 @@ describe('_TN', () => {
expect(helpers._TN`${schema}.${table}`).toEqual({schema: 'ss', table: 'tt'});
expect(helpers._TN`${schema}.${table}.`).toEqual({schema: 'ss', table: 'tt'});
});
it('must support null parameters', () => {
const schema = null, table = null;
expect(helpers._TN`${schema}.${table}`).toEqual({table: ''});
expect(helpers._TN`ss.${table}`).toEqual({schema: 'ss', table: ''});
expect(helpers._TN`${schema}.tt`).toEqual({table: 'tt'});
});
it('must support undefined parameters', () => {
const schema = undefined, table = undefined;
expect(helpers._TN`${schema}.${table}`).toEqual({table: ''});
expect(helpers._TN`ss.${table}`).toEqual({schema: 'ss', table: ''});
expect(helpers._TN`${schema}.tt`).toEqual({table: 'tt'});
});
});
});

0 comments on commit bf10682

Please sign in to comment.