Skip to main content

@Column

@Column maps a class property to a database column. See Data Columns for the full guide, including the enum/parse/ serialize examples.

function Column(type?: DataType): PropertyDecorator;
function Column(options?: ColumnFieldOptions): PropertyDecorator;
  • @Column(type) — shorthand that only sets dataType.
  • @Column(options) — the full ColumnFieldOptions form.
  • @Column() — every option inferred (see below).
import { Column, DataType, Entity } from '@sqb/connect';

@Entity('customers')
class Customer {
@Column()
declare givenName: string;

@Column(DataType.CHAR)
declare gender: string;

@Column({ fieldName: 'birth_date', dataType: DataType.DATE, exclusive: true })
declare birthDate?: Date;
}

Type inference

@Column infers type/dataType for you using TypeScript's design-time reflection metadata (Reflect.getMetadata('design:type', ...), which requires emitDecoratorMetadata):

  • If you don't pass type, it's read from the property's declared TS type. If that type is Array, @Column sets type: String, isArray: true instead. If it's another @Entity-decorated class, @Column sets dataType: DataType.JSON automatically (a nested entity stored as a JSON column — different from @Embedded, which spreads a nested object across prefixed sibling columns of the same table).
  • If you don't pass dataType (and none was inferred from a nested-entity type above), it's derived from type (BooleanBOOL, NumberNUMBER, DateTIMESTAMP, ArrayVARCHAR+isArray: true, BufferBINARY, default→VARCHAR).
  • Conversely, passing dataType without type fills type in from the reverse mapping.

@Column sets no other implicit defaults — notNull, length, precision, etc. are left undefined unless specified. See Data Columns → Type inference for the full mapping tables.

Options

See ColumnFieldOptions for the full field reference (fieldName, dataType, default, isArray, enum, length, precision, scale, collation, autoGenerated, notNull, noUpdate, noInsert, parse, serialize, hidden, exclusive).