Skip to main content

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 like pgTable, 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

Use pgTableCreator 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 InferSelectModel and InferInsertModel for 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
Changing your schema requires running migrations. Never modify the database directly in production.

Next Steps

Database Connection

Learn how to connect to your database

Queries

Start querying your database