Skip to main content

SQLite Drivers

Drizzle ORM supports SQLite through multiple drivers optimized for different JavaScript runtimes and deployment environments.

better-sqlite3

Synchronous SQLite driver for Node.js with excellent performance.

Installation

Basic Usage

Database Options

Performance Optimizations

WAL Mode (Write-Ahead Logging)

WAL mode significantly improves write performance and allows concurrent reads during writes.

Accessing the Client


libSQL (Turso)

Driver for libSQL databases, including Turso’s edge database platform.

Installation

Basic Usage

Embedded Replicas (Hybrid)

Combine local SQLite with remote Turso database for optimal performance:

Environment Variables (Turso)

Get these from your Turso dashboard:

Advanced Options


Cloudflare D1

SQLite driver for Cloudflare Workers and Pages.

Installation

Basic Usage

Worker Configuration

In your wrangler.toml:

Batch Queries

D1 supports efficient batch operations:

Local Development

D1 is optimized for edge deployment. For local development or Node.js, use better-sqlite3 or libSQL instead.

Choosing a Driver

Recommended: better-sqlite3
  • Synchronous API (simpler code)
  • Excellent performance
  • Full SQLite feature support
  • Native Node.js addon

Additional SQLite Drivers

Bun SQLite

For Bun runtime:

Expo SQLite

For React Native with Expo:

sql.js

SQLite compiled to WebAssembly:

File Locations

Relative Path

Absolute Path

Temporary Database

Mock Database for Testing

All SQLite drivers support mock instances:

Common Operations

Enable Foreign Keys

Backup Database

Vacuum

Analyze