Reliable, fast, zero-dependency Prisma adapter for Bun's native SQLite.
- Fully-tested - 153 tests including 40 scenarios ported from Prisma's official test suite
- Drop-in replacement - Compatible with
@prisma/adapter-libsqland@prisma/adapter-better-sqlite3 - Production-ready - WAL mode, safe integers, proper error mapping to Prisma codes (P2002, P2003, etc.)
- Zero dependencies - Uses Bun's native
bun:sqlite, no Node.js packages or native binaries - Programmatic migrations - Run migrations from TypeScript, perfect for
:memory:testing - Single binary deployment - Works with
bun build --compile, embed migrations in your executable - Fast - faster than alternatives with 100% correctness
bun add prisma-adapter-bun-sqlite1. Configure Prisma schema:
// prisma/schema.prisma
generator client {
provider = "prisma-client"
engineType = "client"
runtime = "bun"
// Path of the generated code containing Prisma Client. Relative to the directory where sits schema.prisma
output = "./generated"
}
datasource db {
provider = "sqlite"
// Note: In Prisma 7+, the URL is passed via adapter in PrismaClient constructor
// See: https://pris.ly/d/prisma7-client-config
}2. Use the adapter:
import { PrismaClient } from "./path/to/prisma/generated/client";
import { PrismaBunSqlite } from "prisma-adapter-bun-sqlite";
const adapter = new PrismaBunSqlite({ url: "file:./path/to/db.sqlite" });
const prisma = new PrismaClient({ adapter });
const users = await prisma.user.findMany();| Option | Type | Default | Description |
|---|---|---|---|
url |
string |
required | Database path (file:./path/to/db.sqlite) or :memory: |
safeIntegers |
boolean |
true |
Prevent precision loss for BigInt |
timestampFormat |
"iso8601" | "unixepoch-ms" |
"iso8601" |
DateTime storage format (see Timestamp Format) |
shadowDatabaseUrl |
string |
":memory:" |
Shadow DB for migrations |
wal |
boolean | WalConfiguration |
undefined |
WAL mode configuration |
// Production configuration with WAL
const adapter = new PrismaBunSqlite({
url: "file:./path/to/db.sqlite",
safeIntegers: true,
timestampFormat: "iso8601",
shadowDatabaseUrl: ":memory:",
wal: {
enabled: true,
synchronous: "NORMAL", // 2-3x faster than FULL
busyTimeout: 10000,
},
});The adapter supports two DateTime storage formats:
| Format | Storage | Pros | Cons |
|---|---|---|---|
iso8601 (default) |
TEXT |
Human-readable, SQLite date functions work | Slightly larger storage |
unixepoch-ms |
INTEGER |
Compact, fast comparisons | Less human-readable |
Both formats work correctly out of the box, including DateTime aggregate functions (_min, _max).
const adapter = new PrismaBunSqlite({
url: "file:./db.sqlite",
timestampFormat: "unixepoch-ms",
});Full support for all Prisma operations:
- CRUD operations (create, read, update, delete, upsert)
- Relations (one-to-one, one-to-many, many-to-many, cascades)
- Filtering, ordering, pagination, distinct
- Aggregations (count, sum, avg, min, max, groupBy)
- Transactions (interactive and sequential)
- Raw queries (
$queryRaw,$executeRaw) - Migrations (
prisma migrate dev/deploy)
| Prisma | SQLite | Notes |
|---|---|---|
String |
TEXT |
|
Int |
INTEGER |
32-bit |
BigInt |
TEXT |
Safe integer handling |
Float |
REAL |
|
Decimal |
TEXT |
No native decimal in SQLite |
Boolean |
INTEGER |
0/1 |
DateTime |
TEXT/INTEGER |
ISO8601 or Unix ms |
Bytes |
BLOB |
|
Json |
TEXT |
| SQLite Error | Prisma Code | Description |
|---|---|---|
SQLITE_CONSTRAINT_UNIQUE |
P2002 | Unique violation |
SQLITE_CONSTRAINT_FOREIGNKEY |
P2003 | Foreign key violation |
SQLITE_CONSTRAINT_NOTNULL |
P2011 | Null violation |
SQLITE_BUSY |
Timeout | Database locked |
Standard Prisma CLI works normally:
bunx --bun prisma migrate dev
bunx --bun prisma migrate deployRun migrations from TypeScript - perfect for testing and standalone binaries:
import {
PrismaBunSqlite,
runMigrations,
loadMigrationsFromDir,
createTestDatabase
} from "prisma-adapter-bun-sqlite";
// Option 1: Load from filesystem
const migrations = await loadMigrationsFromDir("./prisma/migrations");
const factory = new PrismaBunSqlite({ url: "file:./path/to/db.sqlite" });
const adapter = await factory.connect();
await runMigrations(adapter, migrations);
// Option 2: In-memory database for tests (fast!)
const adapter = await createTestDatabase([
{ name: "001_init", sql: "CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT);" }
]);
const prisma = new PrismaClient({ adapter });Embed migrations in a single executable:
// build.ts - compile with: bun build --compile ./build.ts
import { PrismaBunSqlite, runMigrations } from "prisma-adapter-bun-sqlite";
import { PrismaClient } from "@prisma/client";
// Migrations embedded at build time
const migrations = [
{ name: "001_init", sql: "CREATE TABLE users (id INTEGER PRIMARY KEY);" }
];
const factory = new PrismaBunSqlite({ url: "file:./path/to/db.sqlite" });
const adapter = await factory.connect();
await runMigrations(adapter, migrations, { logger: () => {} });
const prisma = new PrismaClient({ adapter });
// Your app logic...| Requirement | Version |
|---|---|
| Bun | >= 1.3.0 |
| Prisma | >= 7.0.0 |
| Runtime | Support |
|---|---|
| Bun | ✅ |
| Node.js | ❌ (use better-sqlite3 adapter) |
| Browser | ❌ |
Optional runtime validation to verify your SQLite database is configured correctly:
import { checkWalMode, checkForeignKeys } from "prisma-adapter-bun-sqlite";
// Or: import { checkWalMode, checkForeignKeys } from "prisma-adapter-bun-sqlite/sanity-check";
// At application startup
await checkForeignKeys(prisma); // Throws if foreign_keys != 1
await checkWalMode(prisma); // Throws if journal_mode != "wal"Validates that foreign key constraints are enabled. SQLite disables these by default, which can lead to orphaned records and data integrity issues.
Note: If using PrismaBunSqlite, foreign keys are enabled by default.
Validates that WAL (Write-Ahead Logging) mode is enabled. WAL mode provides better concurrency and performance for most workloads.
Both functions throw descriptive errors with the actual vs expected values and remediation instructions:
Error: SQLite foreign key constraints are not enabled.
Expected foreign_keys = 1, got 0.
Enable foreign keys by running: PRAGMA foreign_keys = ON;
- Bun only - Requires Bun's native
bun:sqlite - SQLite only - Not a PostgreSQL/MySQL adapter
- Single writer - SQLite limitation (readers unlimited)
- Local only - No network support (use libsql for Turso)
- SERIALIZABLE only - SQLite's only isolation level
See ARCHITECTURE.md for implementation details, design decisions, and comparison with official Prisma adapters.
git clone https://github.com/mmvsk/prisma-adapter-bun-sqlite.git
cd prisma-adapter-bun-sqlite
bun install
bun testSee ARCHITECTURE.md before contributing.
MIT