Introduction
Drizzle DuckDB brings Drizzle ORM to DuckDB, an in-process analytical database.
Install
@duckdbfan/drizzle-duckdb.
What is Drizzle DuckDB?
This package is a DuckDB dialect adapter for Drizzle ORM. It provides:
- Type-safe queries: Full TypeScript inference with Drizzle’s query builder
- DuckDB-native types: Support for STRUCT, MAP, LIST, JSON, and other DuckDB-specific types
- Postgres compatibility: Uses Drizzle’s familiar
pg-coreschema definitions - Analytical power: Leverage DuckDB’s columnar engine for fast analytics
When to Use DuckDB
DuckDB excels at:
- Analytical queries: Aggregations, window functions, complex joins
- Large dataset processing: Columnar storage and vectorized execution
- Local-first applications: In-process database, no server required
- Data transformation: Read/write Parquet, CSV, JSON directly
DuckDB is less suited for:
- High-frequency OLTP: Many small insert/update operations
- Real-time transactional workloads: Use Postgres instead
Quick Example
import { DuckDBInstance } from '@duckdb/node-api';
import { drizzle } from '@duckdbfan/drizzle-duckdb';
import { pgTable, integer, text } from 'drizzle-orm/pg-core';
// Define your schema
const users = pgTable('users', {
id: integer('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull(),
});
// Connect to DuckDB
const instance = await DuckDBInstance.create(':memory:');
const connection = await instance.connect();
const db = drizzle(connection);
// Query with full type safety
const allUsers = await db.select().from(users);
// ^? { id: number; name: string; email: string }[]
Status
Experimental
This package is experimental. Core query building, migrations, and type inference work well. Some DuckDB-specific types and edge cases are still being refined.
Next Steps
- Installation: set up the package
- Quick Start: build your first query
- Coming from Postgres: migration guide for Drizzle users