Type Signature
Overview
ColumnType allows you to specify different types for select, insert, and update operations on a database column. This is particularly useful for:
- Database-generated columns (IDs, timestamps)
- Columns with different input/output formats (dates as strings for insert, Date objects for select)
- Read-only columns that can’t be inserted or updated
Type Parameters
The TypeScript type returned when selecting this column from the database.
The TypeScript type accepted when inserting this column. Defaults to
SelectType if not specified.The TypeScript type accepted when updating this column. Defaults to
SelectType if not specified.Examples
Database-Generated Column
Make a column optional in inserts and updates (useful for auto-incrementing IDs):The
Generated<T> type is a shortcut for this pattern.Read-Only Column
Prevent insertion and update of a column:The
GeneratedAlways<T> type is a shortcut for this pattern.Different Types Per Operation
Accept strings for insert, but prevent updates and return Date objects for selects:Related Types
Generated<T>- Shortcut for database-generated columnsGeneratedAlways<T>- Shortcut for always-generated columnsSelectable<T>- Extract select types from a table interfaceInsertable<T>- Extract insert types from a table interfaceUpdateable<T>- Extract update types from a table interface