Skip to content

Commit

Permalink
extending type TableName.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Jun 20, 2016
1 parent a59e915 commit 8d0969b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion jsdoc/fixLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 17 additions & 2 deletions lib/helpers/tableName.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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
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": "4.7.3",
"version": "4.7.4",
"description": "Promises interface for PostgreSQL",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 8d0969b

Please sign in to comment.