From 8d0969b281083c382ca49b38b929d216c2a4234f Mon Sep 17 00:00:00 2001 From: Vitaly Tomilov Date: Mon, 20 Jun 2016 09:28:37 +0100 Subject: [PATCH] extending type TableName. --- jsdoc/fixLinks.js | 3 ++- lib/helpers/tableName.js | 19 +++++++++++++++++-- package.json | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/jsdoc/fixLinks.js b/jsdoc/fixLinks.js index 58a97e71..5f6a9fe0 100644 --- a/jsdoc/fixLinks.js +++ b/jsdoc/fixLinks.js @@ -24,7 +24,8 @@ var links = { "ES6 generator": "https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/function*", "Performance Boost": "https://github.com/vitaly-t/pg-promise/wiki/Performance-Boost", "Prepared Statement": "http://www.postgresql.org/docs/9.5/static/sql-prepare.html", - "Prepared Statements": "http://www.postgresql.org/docs/9.5/static/sql-prepare.html" + "Prepared Statements": "http://www.postgresql.org/docs/9.5/static/sql-prepare.html", + "Custom Type Formatting": "https://github.com/vitaly-t/pg-promise#custom-type-formatting" }; function fixLinks(source) { diff --git a/lib/helpers/tableName.js b/lib/helpers/tableName.js index d1dec43a..78d3bd7a 100644 --- a/lib/helpers/tableName.js +++ b/lib/helpers/tableName.js @@ -8,13 +8,18 @@ var $npm = { /** * @class helpers.TableName * @description - * + * * **Alternative Syntax:** `TableName({table, [schema]})` ⇒ {@link helpers.TableName} * * Prepares and escapes a full table name that can be injected into queries directly. * * This is a read-only type that can be used wherever parameter `table` is supported. * + * **Added in v.4.7.4:** + * + * Support for $[Custom Type Formatting], i.e. you can use the type directly as a formatting parameter, + * without specifying any escaping. + * * @param {String|Object} table * Table name details, depending on the type: * @@ -44,7 +49,11 @@ var $npm = { * var table = new pgp.helpers.TableName('my-table', 'my-schema'); * console.log(table); * //=> "my-schema"."my-table" - * + * + * // From v.4.7.4 we use the type directly: + * pgp.as.format("SELECT $1", table); + * //=> SELECT "my-schema"."my-table" + * */ function TableName(table, schema) { @@ -77,9 +86,15 @@ function TableName(table, schema) { this.name = $npm.formatting.as.name(schema) + '.' + this.name; } + this._rawDBType = true; + Object.freeze(this); } +TableName.prototype.formatDBType = function () { + return this.name; +}; + /** * @method helpers.TableName.toString * @description diff --git a/package.json b/package.json index f213d60d..c73bf04c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pg-promise", - "version": "4.7.3", + "version": "4.7.4", "description": "Promises interface for PostgreSQL", "main": "lib/index.js", "scripts": {