npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prisma-adapter-bun-sqlite

v0.7.0

Published

Prisma driver adapter for Bun's native SQLite (bun:sqlite) - zero dependencies, production-ready

Readme

prisma-adapter-bun-sqlite

Reliable, fast, zero-dependency Prisma adapter for Bun's native SQLite.

npm tests bun prisma

Why This Adapter?

  • Fully-tested - 158 tests including 40 scenarios ported from Prisma's official test suite
  • Drop-in replacement - Compatible with @prisma/adapter-libsql and @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

Installation

bun add prisma-adapter-bun-sqlite

Quick Start

1. 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();

Configuration

| 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,
  },
});

Timestamp Format

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",
});

Features

Prisma Support

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)

Type Conversions

| 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 | |

Error Mapping

| 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 |

Migrations

CLI Migrations

Standard Prisma CLI works normally:

bunx --bun prisma migrate dev
bunx --bun prisma migrate deploy

Programmatic Migrations

Run 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 });

Standalone Binary

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...

Requirements

| Requirement | Version | |-------------|---------| | Bun | >= 1.3.0 | | Prisma | >= 7.0.0 |

Runtime Support

| Runtime | Support | |---------|---------| | Bun | ✅ | | Node.js | ❌ (use better-sqlite3 adapter) | | Browser | ❌ |

Sanity Checks

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"

checkForeignKeys(prisma)

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.

checkWalMode(prisma)

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;

Limitations

  • 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

Architecture

See ARCHITECTURE.md for implementation details, design decisions, and comparison with official Prisma adapters.

Contributing

git clone https://github.com/mmvsk/prisma-adapter-bun-sqlite.git
cd prisma-adapter-bun-sqlite
bun install
bun test

See ARCHITECTURE.md before contributing.

License

MIT

Links