What it is
idb-client-generator is a Prisma generator that produces a fully client-side ORM backed by IndexedDB, with the same API as the real Prisma Client: same models, same operations, same argument shapes. IndexedDB is the browser's built-in transactional database. The idea is that apps built on Prisma can go offline-first without giving up the developer experience. You write the same .create(), .findMany() and .update() calls you already know, but they run in the browser instead of against a server.
const idbClient = await PrismaIDBClient.createClient();
await idbClient.user.create({
data: { name: "Alice", email: "alice@example.com" },
});
const users = await idbClient.user.findMany();
It lives under its own GitHub org and domain (prisma-idb.dev) rather than as a script buried in some other repo, since it's meant to be used as a real dependency.
The problem
Raw IndexedDB has a low-level API. Even with the idb wrapper library, a query across relations means manual index lookups, joins written in application code and no generated types. A Prisma query for the same data is one call with where, include and orderBy. The generator targets teams that already model their data in Prisma and want the same queries in the browser.
How it works
The package is a Prisma generator, which Prisma runs during prisma generate. The generator reads the schema through DMMF (Data Model Meta Format), Prisma's in-memory description of the models. It then writes TypeScript source files into the configured output directory.
Getting the API to actually match Prisma's meant generating types dynamically off a project's own Prisma schema at build time, instead of hand-writing a fixed set of models.
The code lives in packages/generator/src:
| Path | Output |
|---|---|
generator.ts, helpers/parseGeneratorConfig.ts | Entry point and generator options |
fileCreators/prisma-idb-client/ | The PrismaIDBClient class and one class per model |
.../models/api/ | One file per Prisma operation, such as findMany, upsert and updateMany |
fileCreators/idb-utils/ | Filters, list filters, update handlers and comparators for each scalar type |
fileCreators/validators/, enums/ | Validators and enums |
fileCreators/outbox/, apply-pull/, batch-processor/ | Optional sync code |
Relations are not stored as fields in IndexedDB records. The generated client resolves them at query time when a call uses include. packages/generator/DMMF-internals.md records the DMMF details the code depends on, such as how composite keys and foreign key sides appear.
Optional sync
Setting outboxSync = true and a rootModel in the generator block adds a sync layer.
- Each local write also queues an event in an outbox, so pushes can retry.
- The server checks each event against an ownership graph that leads from every record back to the root model, usually
User. - The client pulls a server-authoritative changelog and applies it.
Synced models need client-generated IDs, such as cuid() or uuid(), so local creates need no server round trip.
Two tracks in one repository
The repository also contains a second implementation in packages/prisma-orm/. It targets the Prisma 8 extension architecture with separate driver, adapter and target packages. The README labels the generator as stable and the Prisma 8 stack as a preview.
Why a second track: migrations
The hardest problem in this project was not a generator bug. It was schema migrations.
IndexedDB changes its stores and indexes only during a versioned upgrade. A real migration pipeline therefore has to track schema versions, diff them and replay the steps in the browser. I tried to design one from scratch for the generator and kept postponing it. I could not get it complete or correct enough. It would have been a large new system, separate from the rest of the Prisma generator.
The Prisma 8 contract model changed that. A contract is a description of the data model with a storage hash. The runtime compares that hash with the schema the database actually has. Migrations form a graph between contracts. The framework supports any database stack, not just SQL. The Prisma 8 track uses it like this:
- The build generates a contract space and bundles it into the app.
- Migration operations lower to IndexedDB operations.
- An extension framework carries the sync layer.
That is much easier to work with than a hand-built pipeline.
Testing
The test suite had to prove that every query returns the same result from real Prisma and from this client. I wrote about the harder part of that separately in My best TypeScript work. It turned out to be testing: verifying that every query type produces identical results across the real Prisma client and this one, with full type safety on the test calls themselves.
The apps/usage app holds 62 Playwright specs. They cover model queries, filters, nested writes, relation filters and scalar-list operations. The repository's docs/testing-guidelines.md sets the policy: a new test must name the regression it catches, and tests should prefer real collaborators over mocks.
Design decisions
The architecture decision records (ADRs) in packages/prisma-orm/docs/adrs/ document the Prisma 8 stack. These choices apply to that stack.
No await inside IndexedDB transactions. A transaction commits when it has no pending requests and the task finishes. Awaiting an unrelated promise lets it commit early, and the next request fails. The driver chains requests through callbacks instead (ADR 005). The trade-off is more verbose code and a rule that the type system cannot enforce. Tests with fake-indexeddb do not always reproduce browser timing, so Playwright specs run in real Chromium and WebKit.
The client enforces foreign keys. IndexedDB has no foreign keys or ON DELETE actions. The client checks parents on every write and runs referential actions in the same transaction (ADR 009). Both actions default to restrict, which rejects the same changes as Postgres's default, so a synced client and server agree.
A query planner that never decides what matches. The planner picks a primary-key or index path to narrow the search. The ORM then reapplies the full filter to every returned row (ADR 021). The chosen ranges may include rows that do not match, but never omit one that does, so the refilter gives correct results. Queries it cannot index fall back to a full scan.
Sync authorization follows the schema. The server derives an ownership graph from the schema's relations and rejects pushes outside the caller's scope (ADR 014). Structure replaces a hand-written permission list.
Rejected pushes reconcile to the server row. When the server permanently rejects a write, the client replaces its local row with the server's version (ADR 022). The rejected event stays in the outbox. A CRDT (conflict-free replicated data type) was rejected because it would replace the relational model and constraints. The ADR states the cost: when two offline devices create the same unique key, the second device's data disappears from view.
Use it in a project
Prerequisites: a Prisma project with prisma and @prisma/client installed.
-
Install the dependencies.
pnpm add idb pnpm add -D @prisma-idb/idb-client-generator -
Add the generator to
schema.prisma.generator prismaIDB { provider = "idb-client-generator" output = "./prisma-idb" } -
Generate the client.
pnpm exec prisma generate -
Import
PrismaIDBClientfrom the output directory and callcreateClient(), as in the example above.
Reference
| Item | Value |
|---|---|
| npm package | @prisma-idb/idb-client-generator |
| Peer dependencies | idb 8, prisma and @prisma/client 6 or 7; uuid and @paralleldrive/cuid2 optional |
| Node.js | 20 or newer |
| Monorepo tooling | pnpm, Turborepo, Changesets |
| Documentation | prisma-idb.dev |
| Live demo | kanban.prisma-idb.dev, an offline-first kanban board |
| Directory | Contents |
|---|---|
packages/generator | The generator package |
packages/prisma-orm/ | Prisma 8 stack: client-idb, runtime-idb, adapter-idb, driver-idb, target-idb, family-idb, and sync packages |
apps/usage | Playwright tests for the generated client |
apps/docs | Documentation site |
apps/kanban-example | Sync demo app |
Outcome
- The first commit is dated 2024-10-12. The latest commit at the time of writing is dated 2026-10-19, with 1,896 commits in total.
- The generator is published on npm. The first version is dated 2024-12-01, and the latest, 0.38.1, is dated 2026-06-22.
- The repository is MIT licensed and has 20 GitHub stars.
- The Prisma 8 packages are released at 0.13.0 (the sync packages at 0.7 and 0.8) and are marked as a preview in the README.
- No outside project uses the library yet. Only the kanban example apps do. It is the planned foundation for MyFit v4, which needs to work fully offline, sync when the connection returns, and keep authorization and data safety intact. See MyFit.