Skip to main content

Field

Represents a column reference, optionally schema/table-qualified and aliased. Select builds Field instances internally for every string column you pass; use the constructor directly only when you need to attach a dataType/isArray hint (typically for use with strict comparisons).

Constructor

Field(expression: string, dataType?: DataType, isArray?: boolean): Field
Field(args: { expression: string; dataType?: DataType; isArray?: boolean }): Field
new Field(...): Field

Dual-callable. expression must match [[schema.]table.]field[ [as] alias] — anything else throws a TypeError ("does not match table column format"). A bare * is allowed and never gets an alias, even if one is given.

import { Field, DataType } from '@sqb/builder';

Field('t.field1 f1', DataType.VARCHAR, false);
Field({ expression: 't.field1 f1', dataType: DataType.VARCHAR });

Properties

KeyTypeReadonlyDescription
_typeSerializationType.FIELD_NAMEYesDiscriminates this node during serialization.
_fieldstringNoThe column name (or *).
_tablestring | undefinedNoTable qualifier, if present in the expression.
_schemastring | undefinedNoSchema qualifier, if present in the expression.
_aliasstring | undefinedNoAlias, if present in the expression (never set for *).
_dataTypeDataType | undefinedNoOptional data type hint.
_isArrayboolean | undefinedNoOptional array-field hint.

Methods

Field has no chainable methods of its own — it exposes only its serialization logic. Reserved words in _field/_alias are escaped (double-quoted) automatically when serialized without a table/schema qualifier.

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

Select('with').from('customers').generate().sql;
// select "with" from customers

Select('schema1.table1.field1 f1').from('customers').generate().sql;
// select schema1.table1.field1 as f1 from customers

See also