Skip to main content
zerotal

Documentation


Documentation / @zerotal/orm / index / ColumnOptions

Interface: ColumnOptions

Defined in: packages/orm/src/model/decorators/column.ts:70

Full option object accepted by @column({ ... }).

Every string shorthand (ColumnShorthand) resolves to one of these; use the object form directly when you need nullable, default, a custom cast, or to mark a primary key.

Remarks

The registered type drives schema generation / auto-migration, while cast drives runtime serialization of the attribute value (see the field docs below). A cast is also mirrored onto the model class's static casts map at registration time.

Example

@column({ type: "string", nullable: true, default: "guest" })
nickname?: string | null;

@column({ type: "json", cast: "array", default: [] })
tags!: string[];

@column({ cast: new MoneyCast() })
price!: number;

Properties

type?

optional type?: "string" | "number" | "boolean" | "json" | "datetime"

Defined in: packages/orm/src/model/decorators/column.ts:72

Logical storage type; drives schema generation and auto-migration.

Default

"string"

primary?

optional primary?: boolean

Defined in: packages/orm/src/model/decorators/column.ts:74

Mark this column as the table's primary key.


nullable?

optional nullable?: boolean

Defined in: packages/orm/src/model/decorators/column.ts:76

Allow SQL NULL for this column.


default?

optional default?: unknown

Defined in: packages/orm/src/model/decorators/column.ts:78

Default value applied when none is provided.


cast?

optional cast?: "boolean" | "json" | "date" | "array" | "datetime" | "integer" | "float" | "enum" | "immutable_datetime" | `decimal:${number}` | { get?: (dbValue) => unknown; set?: (jsValue) => unknown; } | CastContract<unknown>

Defined in: packages/orm/src/model/decorators/column.ts:91

Shorthand cast types automatically serialize/deserialize the column value. Can also be a custom object with get/set functions for full control.

  • 'datetime' — Carbon on read, ISO string on write (recommended for dates)
  • 'date' — native Date on read, ISO string on write
  • 'array' / 'json' — JSON.parse on read, JSON.stringify on write
  • 'boolean' — coerces 0/1 integers; writes 0 or 1
  • 'integer' — parseInt on both read and write
  • 'float' — parseFloat on both read and write
  • 'enum' — pass-through; pairs with enumValues for TS enum columns

enumValues?

optional enumValues?: Record<string, string | number>

Defined in: packages/orm/src/model/decorators/column.ts:108

Enum object (e.g. the imported TS enum) used alongside cast: 'enum'.