Skip to main content

Type Signatures

Overview

These utility types are shortcuts for common patterns when working with database-generated columns:
  • Generated<T> - For columns that are optional in inserts and updates (e.g., auto-increment IDs, default values)
  • GeneratedAlways<T> - For columns that cannot be inserted or updated (e.g., GENERATED ALWAYS AS IDENTITY columns)

Generated

The Generated<T> type is useful for columns that the database can generate automatically, but can also be provided manually.

Type Parameters

type
required
The TypeScript type for the column across all operations.

Behavior

  • Select: Returns type S
  • Insert: Accepts S | undefined (optional)
  • Update: Accepts S (optional, as all update fields are optional)

Examples

Auto-Increment ID

Timestamp with Default Value

GeneratedAlways

The GeneratedAlways<T> type is for columns that are always generated by the database and cannot be manually set.

Type Parameters

type
required
The TypeScript type returned when selecting this column.

Behavior

  • Select: Returns type S
  • Insert: Not allowed (never)
  • Update: Not allowed (never)

Examples

PostgreSQL GENERATED ALWAYS AS IDENTITY

Computed Columns

Comparison

Source

View source on GitHub