Documentation Index Fetch the complete documentation index at: https://mintlify.com/drizzle-team/drizzle-orm/llms.txt
Use this file to discover all available pages before exploring further.
Columns define the structure and data types of your tables. Drizzle provides database-specific column types with full TypeScript inference.
Column modifiers
All column types support these common modifiers:
import { pgTable , text , integer } from 'drizzle-orm/pg-core' ;
export const users = pgTable ( 'users' , {
id: integer ( 'id' ). primaryKey (),
name: text ( 'name' ). notNull (),
email: text ( 'email' ). notNull (). unique (),
bio: text ( 'bio' ). default ( '' ),
status: text ( 'status' ). default ( 'active' ),
});
Available modifiers
.notNull()
Makes the column required (NOT NULL constraint) name : text ( 'name' ). notNull ()
.default()
Sets a default value for the column status : text ( 'status' ). default ( 'active' )
.primaryKey()
Marks the column as the primary key id : serial ( 'id' ). primaryKey ()
.unique()
Adds a unique constraint email : text ( 'email' ). unique ()
.references()
Creates a foreign key reference authorId : integer ( 'author_id' ). references (() => users . id )
PostgreSQL column types
Integer types
import { smallint } from 'drizzle-orm/pg-core' ;
// 16-bit integer (-32,768 to 32,767)
age : smallint ( 'age' )
Serial (auto-increment) types
serial
bigserial
smallserial
import { serial } from 'drizzle-orm/pg-core' ;
// Auto-incrementing 32-bit integer
id : serial ( 'id' ). primaryKey ()
Text types
import { text } from 'drizzle-orm/pg-core' ;
// Variable unlimited length
description : text ( 'description' )
// With enum values for type safety
status : text ( 'status' , { enum: [ 'active' , 'inactive' ] })
Numeric types
real
doublePrecision
numeric
import { real } from 'drizzle-orm/pg-core' ;
// Single precision floating point (4 bytes)
temperature : real ( 'temperature' )
Boolean type
import { boolean } from 'drizzle-orm/pg-core' ;
isActive : boolean ( 'is_active' ). default ( true )
isVerified : boolean ( 'is_verified' ). notNull (). default ( false )
Date and time types
timestamp
date
time
interval
import { timestamp } from 'drizzle-orm/pg-core' ;
// Returns Date object
createdAt : timestamp ( 'created_at' ). defaultNow ()
// With timezone
updatedAt : timestamp ( 'updated_at' , { withTimezone: true })
// With precision (0-6)
publishedAt : timestamp ( 'published_at' , { precision: 3 })
// String mode
createdAt : timestamp ( 'created_at' , { mode: 'string' })
JSON types
import { json } from 'drizzle-orm/pg-core' ;
// JSON data (stored as text)
metadata : json ( 'metadata' ). $type <{ key : string ; value : number }>()
Network types
import { inet } from 'drizzle-orm/pg-core' ;
// IPv4 or IPv6 address
ipAddress : inet ( 'ip_address' )
Other PostgreSQL types
import { uuid } from 'drizzle-orm/pg-core' ;
// UUID type
id : uuid ( 'id' ). defaultRandom (). primaryKey ()
MySQL column types
Integer types
tinyint
smallint
int
mediumint
bigint
import { tinyint } from 'drizzle-orm/mysql-core' ;
// 8-bit integer
status : tinyint ( 'status' )
Serial type
import { serial } from 'drizzle-orm/mysql-core' ;
// Auto-increment BIGINT UNSIGNED
id : serial ( 'id' ). primaryKey ()
String types
import { varchar } from 'drizzle-orm/mysql-core' ;
email : varchar ( 'email' , { length: 255 })
Numeric types
import { float } from 'drizzle-orm/mysql-core' ;
rating : float ( 'rating' )
Date and time types
datetime
timestamp
date
year
import { datetime } from 'drizzle-orm/mysql-core' ;
createdAt : datetime ( 'created_at' )
Other MySQL types
import { boolean } from 'drizzle-orm/mysql-core' ;
isActive : boolean ( 'is_active' )
SQLite column types
SQLite uses a flexible type system with type affinities:
integer
real
text
blob
numeric
import { integer } from 'drizzle-orm/sqlite-core' ;
// Integer storage
id : integer ( 'id' ). primaryKey ({ autoIncrement: true })
count : integer ( 'count' )
// Boolean mode
isActive : integer ( 'is_active' , { mode: 'boolean' })
// Timestamp mode
createdAt : integer ( 'created_at' , { mode: 'timestamp' })
createdAtMs : integer ( 'created_at_ms' , { mode: 'timestamp_ms' })
Custom column types
Create custom column types for all databases:
import { customType } from 'drizzle-orm/pg-core' ;
const customText = customType < { data: string } > {
dataType () {
return 'text' ;
},
toDriver ( value : string ) : string {
return value . toLowerCase ();
},
fromDriver ( value : string ) : string {
return value . toUpperCase ();
},
});
export const users = pgTable ( 'users' , {
name: customText ( 'name' ),
});
Type inference
Drizzle automatically infers TypeScript types from your schema:
import { pgTable , serial , text , boolean } from 'drizzle-orm/pg-core' ;
export const users = pgTable ( 'users' , {
id: serial ( 'id' ). primaryKey (),
name: text ( 'name' ). notNull (),
email: text ( 'email' ). notNull (),
isActive: boolean ( 'is_active' ). default ( true ),
});
// Inferred type
type User = typeof users . $inferSelect ;
// { id: number; name: string; email: string; isActive: boolean | null }
type NewUser = typeof users . $inferInsert ;
// { id?: number; name: string; email: string; isActive?: boolean | null }