Laizy CMS
Schema

Field Types

All available field types in Laizy schemas, their TypeScript equivalents, default behaviors, and usage examples.

Field Types

Every field in a Laizy schema has a type that determines what kind of data it stores, how it validates input, and what TypeScript type it maps to in the generated client.

Available Types

Laizy supports five field types. Each maps directly to a TypeScript type in the generated client code.

Schema TypeTypeScript TypeDescription
StringstringText content of any length
IntnumberWhole numbers without decimals
FloatnumberDecimal numbers with floating-point precision
Booleanbooleantrue or false values
DateTimeDateISO 8601 timestamps

String

The most common field type. Stores text content of any length, from short titles to full article bodies.

model BlogPost {
  title: String {
    required: true
    maxLength: 200
  }

  content: String {
    required: true
  }

  slug: String {
    required: true
    unique: true
  }

  bio: String
}

Behavior:

  • Accepts any UTF-8 text
  • No length limit unless you set maxLength
  • Can be constrained with required, unique, maxLength, and default
  • Auto-fill default for required fields during migration: "" (empty string)

Generated TypeScript:

export interface BlogPost {
  title: string
  content: string
  slug: string
  bio: string
  // System fields
  id: string
  createdAt: Date
  updatedAt: Date
}

Int

Stores whole numbers. Use this for counts, positions, quantities, or any value that should never have a decimal.

model Product {
  stockCount: Int {
    required: true
    default: 0
  }

  sortOrder: Int
}

Behavior:

  • Accepts integers only (no decimals)
  • Can be combined with required, unique, and default
  • Auto-fill default for required fields during migration: 0
  • Compatible type change from Float (will truncate decimals)

Generated TypeScript:

export interface Product {
  stockCount: number
  sortOrder: number
  id: string
  createdAt: Date
  updatedAt: Date
}

Float

Stores decimal numbers with floating-point precision. Use this for prices, ratings, measurements, or any value that needs decimal places.

model Product {
  price: Float {
    required: true
  }

  rating: Float {
    default: 0
  }
}

Behavior:

  • Accepts any numeric value including decimals
  • Can be combined with required, unique, and default
  • Auto-fill default for required fields during migration: 0.0
  • Compatible type change to/from Int (Int to Float is lossless; Float to Int may lose precision)

Generated TypeScript:

export interface Product {
  price: number
  rating: number
  id: string
  createdAt: Date
  updatedAt: Date
}

Both Int and Float map to TypeScript's number type. The distinction matters for validation and migration behavior, not for the generated client types.

Boolean

Stores true or false values. Use this for toggles, feature flags, and publish states.

model Feature {
  isEnabled: Boolean {
    default: false
  }

  isPublic: Boolean {
    required: true
  }
}

Behavior:

  • Accepts only true or false
  • Works well with default for initial state
  • Auto-fill default for required fields during migration: false
  • Cannot be safely converted to/from other types

Generated TypeScript:

export interface Feature {
  isEnabled: boolean
  isPublic: boolean
  id: string
  createdAt: Date
  updatedAt: Date
}

DateTime

Stores timestamps as ISO 8601 date strings. Use this for scheduled publish dates, event times, or any temporal data.

model Event {
  startDate: DateTime {
    required: true
  }

  endDate: DateTime

  publishAt: DateTime
}

Behavior:

  • Accepts ISO 8601 formatted date strings
  • Stored as Date objects in the database
  • Auto-fill default for required fields during migration: null
  • Cannot be safely converted to/from other types

Generated TypeScript:

export interface Event {
  startDate: Date
  endDate: Date
  publishAt: Date
  id: string
  createdAt: Date
  updatedAt: Date
}

System Fields

Every content model automatically includes three system fields that you do not define in your schema. They are added by the generator and managed by Laizy:

FieldTypeDescription
idstringUnique identifier for each content entry
createdAtDateTimestamp when the entry was created
updatedAtDateTimestamp of the last update

You cannot override or configure these fields. They appear in the generated TypeScript interfaces and are returned by all query methods.

Type Safety in the Generated Client

When you run laizy generate, each field type maps to the appropriate TypeScript type. The generated client includes separate interfaces for creating and reading content:

// Read interface — all fields present
export interface BlogPost {
  title: string
  content: string
  slug: string
  id: string
  createdAt: Date
  updatedAt: Date
}

// Create input — only user-defined fields, respects required/optional
export interface CreateBlogPostInput {
  title: string      // required in schema
  content: string    // required in schema
  slug: string       // required in schema
}

// Update input — all fields optional for partial updates
export interface UpdateBlogPostInput {
  title?: string
  content?: string
  slug?: string
}

Fields with default constraints are excluded from the Create input since the system provides a value if omitted. Fields without required: true are marked optional with ?.

Type Conversion During Migrations

When you change a field's type in your schema and run laizy sync, the migration planner classifies the change by safety level:

FromToImpactNotes
StringAnyWarningString values may not convert cleanly
IntFloatWarningLossless conversion
FloatIntWarningMay lose decimal precision
BooleanAny non-BooleanDestructiveIncompatible conversion
DateTimeAny non-DateTimeDestructiveIncompatible conversion

The sync command will show these impacts in the migration plan and ask for confirmation before applying destructive changes.

Next Steps

  • Constraints -- Control validation with required, unique, default, and maxLength
  • Schema Syntax -- Full reference for the .laizy schema language
  • Migrations -- How schema sync handles changes safely

On this page