Skip to main content

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

SelectType
type
required
The TypeScript type returned when selecting this column from the database.
InsertType
type
default:"SelectType"
The TypeScript type accepted when inserting this column. Defaults to SelectType if not specified.
UpdateType
type
default:"SelectType"
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:
With this definition:

Source

View source on GitHub