Skip to main content

Function: Enum()

Enum(values): PropertyDecorator

Defined in: src/decorators/EnumDecorator.ts:22

Property decorator restricting a column's value to a specific set of allowed enum strings.

DDL generation behaviour per provider:

  • MySQL / PlanetScale: native ENUM('val1', 'val2') column type.
  • PostgreSQL / Neon / CockroachDB / Supabase: VARCHAR(N) CHECK (col IN ('val1', 'val2')).
  • SQLite / Turso / D1: TEXT CHECK (col IN ('val1', 'val2')).
  • MSSQL: NVARCHAR(N) + column-level CHECK constraint.

The TypeScript property type should be a string union matching the allowed values.

Parameters​

ParameterTypeDescription
valuesstring[]The exhaustive list of allowed enum string values.

Returns​

PropertyDecorator

Usecase​

Status columns, type discriminators, or constrained category fields.

Example​

@Enum(['active', 'inactive', 'suspended'])
status!: 'active' | 'inactive' | 'suspended';