[**Documentation**](../../../../README)

***

[Documentation](../../../../README) / [@zerotal/orm](../../README) / [index](../README) / column

# Function: column()

## Call Signature

> **column**(): `ColumnDecorator`

Defined in: [packages/orm/src/model/decorators/column.ts:243](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/decorators/column.ts#L243)

Map a model property to a database column.

### Returns

`ColumnDecorator`

A class-field decorator that registers the property as a column.

### Remarks

Applied to a field of a `BaseModel` subclass, `@column` registers that property
in the ORM's column metadata (`columnRegistry`), so it participates in
hydration, dirty-tracking, persistence, and schema generation / auto-migration.

The argument may be omitted (defaults to a `"string"` column), given as a
[ColumnShorthand](../type-aliases/ColumnShorthand) string, or given as a full [ColumnOptions](../interfaces/ColumnOptions) object.
Options control the storage `type`, `primary` key, `nullable`, `default`, and —
most importantly — the `cast` that serializes the value between DB and model
(`json`/`array`, `datetime`/`date`, `boolean`, `integer`/`float`, `decimal:n`,
`enum`, or a custom `{ get, set }` / [CastContract](../interfaces/CastContract)). A declared `cast` is
also mirrored onto the class's `static casts` map.

Timestamp and primary-key conventions themselves are configured on the class via
`@table` (see [table](table)); `@column` only maps individual fields.

Registration is anchored at class-definition time by the `@table` decorator (a
Bun 1.3.x standard-decorator workaround), so a model that declares columns must
also carry `@table` — or be auto-discovered from `app/models/`.

### Example

```ts
@table("users")
export class User extends BaseModel {
  @column({ primary: true }) id!: number;

  // No args — defaults to a string column
  @column() name!: string;

  // String shorthand
  @column("integer") age!: number;
  @column("datetime") createdAt!: Carbon;

  // Cast a JSON column to/from an array (reactive when `static reactiveCasts`)
  @column({ type: "json", cast: "array", default: [] }) roles!: string[];

  // Nullable with a custom cast object
  @column({ nullable: true, cast: { get: (v) => v && new URL(String(v)), set: (u) => u?.href } })
  website?: URL | null;
}
```

## Call Signature

> **column**(`type`): `ColumnDecorator`

Defined in: [packages/orm/src/model/decorators/column.ts:244](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/decorators/column.ts#L244)

Map a model property to a database column.

### Parameters

#### type

[`ColumnShorthand`](../type-aliases/ColumnShorthand)

### Returns

`ColumnDecorator`

A class-field decorator that registers the property as a column.

### Remarks

Applied to a field of a `BaseModel` subclass, `@column` registers that property
in the ORM's column metadata (`columnRegistry`), so it participates in
hydration, dirty-tracking, persistence, and schema generation / auto-migration.

The argument may be omitted (defaults to a `"string"` column), given as a
[ColumnShorthand](../type-aliases/ColumnShorthand) string, or given as a full [ColumnOptions](../interfaces/ColumnOptions) object.
Options control the storage `type`, `primary` key, `nullable`, `default`, and —
most importantly — the `cast` that serializes the value between DB and model
(`json`/`array`, `datetime`/`date`, `boolean`, `integer`/`float`, `decimal:n`,
`enum`, or a custom `{ get, set }` / [CastContract](../interfaces/CastContract)). A declared `cast` is
also mirrored onto the class's `static casts` map.

Timestamp and primary-key conventions themselves are configured on the class via
`@table` (see [table](table)); `@column` only maps individual fields.

Registration is anchored at class-definition time by the `@table` decorator (a
Bun 1.3.x standard-decorator workaround), so a model that declares columns must
also carry `@table` — or be auto-discovered from `app/models/`.

### Example

```ts
@table("users")
export class User extends BaseModel {
  @column({ primary: true }) id!: number;

  // No args — defaults to a string column
  @column() name!: string;

  // String shorthand
  @column("integer") age!: number;
  @column("datetime") createdAt!: Carbon;

  // Cast a JSON column to/from an array (reactive when `static reactiveCasts`)
  @column({ type: "json", cast: "array", default: [] }) roles!: string[];

  // Nullable with a custom cast object
  @column({ nullable: true, cast: { get: (v) => v && new URL(String(v)), set: (u) => u?.href } })
  website?: URL | null;
}
```

## Call Signature

> **column**(`options`): `ColumnDecorator`

Defined in: [packages/orm/src/model/decorators/column.ts:245](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/orm/src/model/decorators/column.ts#L245)

Map a model property to a database column.

### Parameters

#### options

[`ColumnOptions`](../interfaces/ColumnOptions)

### Returns

`ColumnDecorator`

A class-field decorator that registers the property as a column.

### Remarks

Applied to a field of a `BaseModel` subclass, `@column` registers that property
in the ORM's column metadata (`columnRegistry`), so it participates in
hydration, dirty-tracking, persistence, and schema generation / auto-migration.

The argument may be omitted (defaults to a `"string"` column), given as a
[ColumnShorthand](../type-aliases/ColumnShorthand) string, or given as a full [ColumnOptions](../interfaces/ColumnOptions) object.
Options control the storage `type`, `primary` key, `nullable`, `default`, and —
most importantly — the `cast` that serializes the value between DB and model
(`json`/`array`, `datetime`/`date`, `boolean`, `integer`/`float`, `decimal:n`,
`enum`, or a custom `{ get, set }` / [CastContract](../interfaces/CastContract)). A declared `cast` is
also mirrored onto the class's `static casts` map.

Timestamp and primary-key conventions themselves are configured on the class via
`@table` (see [table](table)); `@column` only maps individual fields.

Registration is anchored at class-definition time by the `@table` decorator (a
Bun 1.3.x standard-decorator workaround), so a model that declares columns must
also carry `@table` — or be auto-discovered from `app/models/`.

### Example

```ts
@table("users")
export class User extends BaseModel {
  @column({ primary: true }) id!: number;

  // No args — defaults to a string column
  @column() name!: string;

  // String shorthand
  @column("integer") age!: number;
  @column("datetime") createdAt!: Carbon;

  // Cast a JSON column to/from an array (reactive when `static reactiveCasts`)
  @column({ type: "json", cast: "array", default: [] }) roles!: string[];

  // Nullable with a custom cast object
  @column({ nullable: true, cast: { get: (v) => v && new URL(String(v)), set: (u) => u?.href } })
  website?: URL | null;
}
```
