Overview
Drizzle ORM provides a type-safe, declarative way to define your database schema using TypeScript. Schemas are defined using table builders specific to your database dialect (PostgreSQL, MySQL, or SQLite).Table Declaration
Basic Table Definition
Tables are defined using dialect-specific functions likepgTable, mysqlTable, or sqliteTable.
Column Types
PostgreSQL Column Types
Drizzle supports all PostgreSQL column types with full type inference:Column Modifiers
All column types support common modifiers:Type Inference
Drizzle automatically infers TypeScript types from your schema:Table Constraints
Composite Primary Keys
Indexes
Foreign Keys
Check Constraints
Schemas and Namespaces
PostgreSQL Schemas
Custom Table Names
UsepgTableCreator to add prefixes to table names:
Custom Column Types
Create custom column types with specific behavior:Best Practices
- Export schemas: Always export your table definitions for use in queries and migrations
- Use type inference: Leverage
InferSelectModelandInferInsertModelfor type safety - Column naming: Use snake_case for database columns, Drizzle handles conversion
- Constraints: Define constraints in the schema for data integrity
- Indexes: Add indexes for frequently queried columns
Next Steps
Database Connection
Learn how to connect to your database
Queries
Start querying your database