Column Types
SQLite uses a dynamic type system with type affinity. Drizzle provides typed column builders for common use cases.
integer()
Defines an integer column. Supports multiple modes for different data types.
Signature
Basic Integer
Timestamp Mode
Stores dates as Unix timestamps (seconds since epoch).
Timestamp Milliseconds Mode
Stores dates as Unix timestamps in milliseconds.
Boolean Mode
Stores booleans as integers (0 or 1).
Primary Key Options
text()
Defines a text column. Supports plain text, enums, and JSON.
Signature
Basic Text
Enum Text
Enforces type safety with predefined values.
JSON Mode
Stores JSON data as text with automatic serialization.
real()
Defines a real (floating-point) column.
numeric()
Defines a numeric column. Useful for precise decimal values.
Signature
String Mode (Default)
Preserves precision as string.
Number Mode
Converts to JavaScript number.
BigInt Mode
Converts to JavaScript bigint.
blob()
Defines a blob (binary) column. Supports buffer, JSON, and bigint modes.
Signature
Buffer Mode (Default)
Stores binary data.
JSON Mode
Stores JSON as binary. Note: Use text('...', { mode: 'json' }) instead for JSON functions support.
SQLite’s JSON functions don’t work with blob columns. Use text('...', { mode: 'json' }) if you need JSON functions.
BigInt Mode
Stores bigint values as binary.
Column Modifiers
All column builders support these chainable methods:
notNull()
Makes the column non-nullable.
default()
Sets a default value.
primaryKey()
Marks the column as the primary key.
unique()
Adds a unique constraint.
references()
Defines a foreign key reference.
$type()
Overrides the TypeScript type.
$default()
Sets a runtime default value function.
$onUpdate()
Sets a function to run on every update.
$onUpdateFn()
Sets a SQL expression to run on update.
Generated Columns
SQLite supports generated columns (virtual and stored).
Type Inference
Drizzle automatically infers TypeScript types from column definitions: