@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 setsdataType.@Column(options)— the fullColumnFieldOptionsform.@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 isArray,@Columnsetstype: String, isArray: trueinstead. If it's another@Entity-decorated class,@ColumnsetsdataType: DataType.JSONautomatically (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-entitytypeabove), it's derived fromtype(Boolean→BOOL,Number→NUMBER,Date→TIMESTAMP,Array→VARCHAR+isArray: true,Buffer→BINARY, default→VARCHAR). - Conversely, passing
dataTypewithouttypefillstypein 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).