prisma-sqlite-bun-adapter
v1.0.0-alpha1
Published
Prisma 7 driver adapter backed by Bun's built-in bun:sqlite
Maintainers
Readme
prisma-sqlite-bun-adapter
A Prisma 7 driver adapter backed by Bun's built-in
bun:sqlite.
Prisma 7 requires a driver adapter for every datasource, and both official
SQLite adapters depend on native modules that Bun cannot load — better-sqlite3
is rejected by Bun outright. This
package closes that gap using the SQLite driver Bun already ships, so there is
nothing to compile and no native dependency.
Install
bun add prisma-sqlite-bun-adapterRequires Bun ≥ 1.2.17 and @prisma/client 7.x.
📖 Full documentation — guides and an API reference generated from the source.
Usage
import { PrismaBunSQLite } from 'prisma-sqlite-bun-adapter'
import { PrismaClient } from './generated/prisma/client'
const adapter = new PrismaBunSQLite({ url: 'file:./dev.db' })
const prisma = new PrismaClient({ adapter })Your schema needs no url — Prisma 7 takes connection details from the adapter
at runtime and from prisma.config.ts for CLI commands:
datasource db {
provider = "sqlite"
}Bring your own connection
Pass a Database you opened yourself to share it with non-Prisma code, load an
extension, or set custom flags:
import { Database } from 'bun:sqlite'
const database = new Database('./dev.db', { strict: true })
const adapter = new PrismaBunSQLite({ database })The adapter will not close a connection you supplied, and will not apply PRAGMAs to it. That handle's lifecycle and configuration stay yours.
Options
new PrismaBunSQLite(
{ url: 'file:./dev.db', readonly: false, create: true, strict: false },
{
timestampFormat: 'iso8601', // or 'unixepoch-ms'
shadowDatabaseUrl: ':memory:',
statementCacheSize: 100, // 0 disables caching
pragmas: false, // see below
},
)PRAGMAs
Off by default. Passing pragmas enables a sensible set for application use:
new PrismaBunSQLite({ url: 'file:./dev.db' }, { pragmas: {} })
// journal_mode = WAL, foreign_keys = ON, busy_timeout = 5000Each is overridable ({ pragmas: { journalMode: 'DELETE', busyTimeout: 0 } }).
foreign_keys is worth calling out: SQLite leaves it off, which means
relations declared in your Prisma schema are not enforced by the database unless
you switch it on.
Migrations
prisma migrate dev, db push, and db pull work under Bun with no extra
setup. Point prisma.config.ts at your database:
import { defineConfig } from 'prisma/config'
export default defineConfig({
schema: 'schema.prisma',
datasource: { url: 'file:./dev.db' },
})bunx prisma migrate dev --name initNote that in Prisma 7.9 the CLI connects using this URL and its own SQLite
handling — migrations do not route through the adapter. The adapter implements
the migration-aware factory (connectToShadowDb) regardless, since that is part
of the interface the schema engine consumes.
Differences from @prisma/adapter-better-sqlite3
The test suite runs a shared corpus through both adapters and asserts identical result sets. Three differences are known and deliberate:
| Difference | Why |
| --- | --- |
| A bound integer read straight back out infers a different column type | The drivers disagree: better-sqlite3 binds every JS number as SQLite REAL, bun:sqlite binds integral ones as INTEGER. Values are unaffected, and so is any column with a declared type, because affinity applies on write. |
| BLOBs from columns with no declared type work here | The official adapter throws UnexpectedTypeError on these — its type inference accepts only ArrayBuffer, while better-sqlite3 returns a Buffer. Reported as prisma/prisma#29868. |
| A failing BEGIN does not deadlock | The official adapter acquires its transaction mutex before BEGIN and only releases it on success, so a failed BEGIN blocks every later transaction on that adapter. |
Prepared statements are also cached per connection (the official adapter re-prepares on every query), which is the main performance difference.
Development
bun install
bun run typecheck
bun run lint
bun test test/unit
bun test test/differential
bun test test/e2e # needs: cd test/e2e && bunx prisma generate --config prisma.config.ts
bun test test/cli
bun run fixtures # regenerate the reference fixture (requires Node)
bun run docs:api # regenerate docs/api from the source JSDoc
cd site && bun install && bun run dev # the documentation siteThe differential fixture is generated under Node, because Bun cannot load
better-sqlite3 in the same process. CI regenerates it and fails on drift, so
it cannot decay into a snapshot of this adapter's own behaviour.
License
MIT
