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 IDENTITYcolumns)
Generated
TheGenerated<T> type is useful for columns that the database can generate automatically, but can also be provided manually.
Type Parameters
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
TheGeneratedAlways<T> type is for columns that are always generated by the database and cannot be manually set.
Type Parameters
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
| Type | Select | Insert | Update | Use Case |
|---|---|---|---|---|
Generated<T> | T | T | undefined | T | Auto-increment IDs, default values |
GeneratedAlways<T> | T | never | never | Identity columns, computed columns |
Related Types
ColumnType<SelectType, InsertType, UpdateType>- The underlying generic typeSelectable<T>- Extract select types from a table interfaceInsertable<T>- Extract insert types from a table interfaceUpdateable<T>- Extract update types from a table interface