Does SQLite Work With Drizzle ORM?
SQLite and Drizzle ORM work excellently together, providing a lightweight, zero-dependency SQL experience perfect for development, testing, and production applications.
Quick Facts
How SQLite Works With Drizzle ORM
Drizzle ORM has first-class support for SQLite through its `drizzle-orm/sqlite-core` and `drizzle-orm/better-sqlite3` (or `sql.js`) packages. SQLite's serverless architecture pairs perfectly with Drizzle's philosophy of being lightweight and TypeScript-first. You define your schema with Drizzle's type-safe builders, and it generates SQL that SQLite executes natively. The developer experience is exceptional: you get compile-time type checking on queries, automatic migrations via Drizzle Kit, and no database server to manage. For desktop apps, Electron projects, or development environments, SQLite with Drizzle eliminates operational complexity while maintaining SQL expressiveness. Drizzle generates clean, readable SQL that runs efficiently on SQLite's query engine, and you can use advanced features like CTEs, window functions, and JSON operations that modern SQLite versions support.
Best Use Cases
Quick Setup
npm install drizzle-orm better-sqlite3 && npm install -D drizzle-kitimport { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';
import { text, integer, sqliteTable } from 'drizzle-orm/sqlite-core';
const sqlite = new Database('app.db');
const db = drizzle(sqlite);
const users = sqliteTable('users', {
id: integer('id').primaryKey(),
name: text('name').notNull(),
email: text('email').unique(),
});
// Type-safe queries
await db.insert(users).values({ name: 'Alice', email: 'alice@example.com' });
const allUsers = await db.select().from(users);
const userById = await db.select().from(users).where(eq(users.id, 1));Known Issues & Gotchas
SQLite has limited concurrent write support; multiple simultaneous writes will queue or fail
Fix: Use connection pooling with better-sqlite3 or batch writes. For high-concurrency scenarios, migrate to PostgreSQL later—Drizzle makes this transition painless.
Foreign key constraints are disabled by default in SQLite
Fix: Enable them explicitly: `PRAGMA foreign_keys = ON;` in your connection setup, or Drizzle will handle this if configured.
Type inference on complex joined queries can be verbose; you may need explicit type annotations
Fix: Use Drizzle's `.as()` helper and explicit type parameters for complex queries to keep code readable.
SQLite doesn't support all PostgreSQL-specific features (e.g., enums, arrays natively)
Fix: Use JSON columns or TEXT with validation, or plan a database migration strategy upfront.
Alternatives
- •PostgreSQL + Drizzle ORM (for production, concurrent writes, and advanced SQL features)
- •SQLite + Prisma (higher-level ORM with built-in migrations, but less transparent SQL)
- •SQLite + TypeORM (more traditional ORM, heavier but with more conventions)
Resources
Related Compatibility Guides
Explore more compatibility guides