helpers.TableName

new TableName(table, schemaopt) → {helpers.TableName}

Alternative Syntax: TableName({table, [schema]})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.

It supports Custom Type Formatting, which means you can use the type directly as a formatting parameter, without specifying any escaping.

Parameters:
Name Type Attributes Description
table string | object

Table name details, depending on the type:

  • table name, if table is a string
  • object {table, [schema]}
schema string <optional>

Database schema name.

When table is passed in as {table, [schema]}, this parameter is ignored.

Properties:
Name Type Description
name string

Formatted/escaped full table name, based on properties schema + table.

table string

Table name.

schema string

Database schema name.

It is undefined when no schema was specified (or if it was an empty string).

Source:
Returns:
Type
helpers.TableName
Example
const table = new pgp.helpers.TableName('my-table', 'my-schema');
console.log(table);
//=> "my-schema"."my-table"

// Formatting the type directly:
pgp.as.format('SELECT * FROM $1', table);
//=> SELECT * FROM "my-schema"."my-table"

Methods

toString() → {string}

Creates a well-formatted string that represents the object.

It is called automatically when writing the object into the console.

Source:
Returns:
Type
string