Skip to main content

TableName

Represents a table reference, optionally schema-qualified and aliased, with optional dialect-specific optimizer hints. .from(), Insert/Update/Delete's tableName argument, and join constructors all build TableName instances internally when you pass a plain string.

Constructor

TableName(tableName: string): TableName
TableName(args: TableName.Args): TableName
new TableName(...): TableName

Dual-callable. A string must match [schema.]table[ [as] alias], otherwise throws a TypeError ("does not match table name format").

import { TableName } from '@sqb/builder';

TableName('customers');
TableName('sales.customers c'); // schema "sales", table "customers", alias "c"
TableName({ schema: 'sales', table: 'customers', alias: 'c' });

TableName.Args

interface Args {
schema?: string;
table: string;
alias?: string;
optimizerHint?: string | string[] | OptimizerHint | OptimizerHint[];
}

interface OptimizerHint {
hint: string;
dialect?: string[];
}

optimizerHint lets you attach dialect-specific query hints (e.g. Oracle's /*+ ... */ hints); rendering them is left to a SerializerExtensionTableName itself only stores them.

Properties

KeyTypeReadonlyDescription
_typeSerializationType.TABLE_NAMEYesDiscriminates this node during serialization.
schemastring | undefinedNoSchema qualifier.
tablestring | undefinedNoTable name.
aliasstring | undefinedNoTable alias.
optimizerHintTableName.OptimizerHint[] | undefinedNoOptimizer hints attached via the object constructor form.

Methods

TableName has no chainable methods — it exposes only its serialization logic (default rendering: [schema.]table[ alias]).

import { Select } from '@sqb/builder';

Select().from('sales.customers c').generate().sql;
// select * from sales.customers c

See also