Type Signature
Overview
Insertable<T> is a utility type that extracts the insert type from all columns in a table interface. It resolves the InsertType from any ColumnType definitions and creates a type representing what you can insert into the table.
Type Parameters
A table interface with column definitions.
Behavior
- Extracts the second type parameter (
InsertType) from eachColumnType<SelectType, InsertType, UpdateType> - For regular types without
ColumnType, uses the type as-is - Fields with nullable insert types (can be
undefinedornull) become optional - Fields with non-nullable insert types remain required
- Excludes columns where
InsertTypeisnever
Examples
Basic Usage
idis optional (becauseGenerated<number>allowsundefinedfor inserts)created_atis astring(notDate) for insertsfirst_nameandlast_nameare required strings
Using with Insert Queries
With GeneratedAlways Columns
Optional vs Required Fields
Different Types for Insert
Common Patterns
Function Parameters
Bulk Inserts
Combining with Selectable
Partial Insertable with Pick
Related Types
ColumnType<SelectType, InsertType, UpdateType>- Define different types for different operationsSelectable<T>- Extract select types from a table interfaceUpdateable<T>- Extract update types from a table interfaceGenerated<T>- Shortcut for database-generated columnsGeneratedAlways<T>- Shortcut for always-generated columns