helpers.TableName

new TableName(table) → {helpers.TableName}

Represents 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.

Filter :alias is an alternative approach to splitting an SQL name into multiple ones.

Parameters:
Name Type Description
table string | object

Table name details, depending on the type:

  • table name, if table is a string
  • object {table, [schema]}
Properties:
Name Type Description
name string

Formatted/escaped full table name, combining schema + table.

table string

Table name.

schema string

Database schema name.

It is undefined when no valid schema was specified.

Source:
See:
Returns:
Type
helpers.TableName
Example
const table = new pgp.helpers.TableName({table: 'my-table', schema: '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

toPostgres(selfopt) → {string}

Custom Type Formatting, based on Symbolic CTF, i.e. the actual method is available only via Symbol:

const ctf = pgp.as.ctf; // Custom Type Formatting symbols namespace
const fullName = tn[ctf.toPostgres]; // tn = an object of type TableName

This is a raw formatting type (rawType = true), i.e. when used as a query-formatting parameter, type TableName injects full table name as raw text.

Parameters:
Name Type Attributes Description
self helpers.TableName <optional>

Optional self-reference, for ES6 arrow functions.

Source:
Returns:

Escaped full table name that includes optional schema name, if specified.

Type
string

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