Skip to content

About

The simplicity and features of the Prisma ORM, emulated in IndexedDB. Perfect for web apps needing structured local storage!

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

20 stars

Watchers

1 watching

Forks

Repository files navigation

Prisma IDB

Prisma IDB — Type-safe IndexedDB with the Prisma API

You already write Prisma on the server. Now write it in the browser.

Type-safe IndexedDB with the Prisma API you already know — offline-first, no server required.

Documentation · Live Demo

Two flavors

Generator (stable) Prisma 8 IDB extension
Package @prisma-idb/idb-client-generator @prisma-idb/client-idb + CLI packages
How it works Prisma generator — runs prisma generate, emits a typed client Prisma 8 driver + adapter + target stack for IndexedDB
Status Stable, published Preview, built on Prisma 8
Source packages/generator packages/prisma-orm/*

The difference (vs raw IndexedDB)

Even with the idb library, querying across relations means manual index lookups, joins in application code, and zero type safety:

const db = await openDB("MyDB", 1);

const posts = await db.getAllFromIndex("posts", "byAuthor", userId);

const result = [];
for (const post of posts) {
  if (!post.published) continue;
  const comments = await db.getAllFromIndex("comments", "byPost", post.id);
  result.push({ ...post, comments });
}
result.sort((a, b) => b.createdAt - a.createdAt);
// manual joins, no types, no filtering

Prisma IDB:

const posts = await idb.post.findMany({
  where: { authorId: userId, published: true },
  include: {
    comments: { orderBy: { createdAt: "desc" } },
  },
  orderBy: { createdAt: "desc" },
});

Same API as Prisma Client. Fully typed. Works offline.

Generator quick start

Install

pnpm add idb
pnpm add @prisma-idb/idb-client-generator --save-dev

Configure

Add the generator to your schema.prisma:

generator prismaIDB {
  provider = "idb-client-generator"
  output   = "./prisma-idb"
}

model Todo {
  id    String  @id @default(cuid())
  title String
  done  Boolean @default(false)
}

Generate & use

pnpm exec prisma generate
import { PrismaIDBClient } from "./prisma-idb";

const idb = await PrismaIDBClient.createClient();

await idb.todo.create({ data: { title: "Ship it", done: false } });

const todos = await idb.todo.findMany({ where: { done: false } });

await idb.todo.update({ where: { id: todoId }, data: { done: true } });

await idb.todo.delete({ where: { id: todoId } });

Optional sync engine

generator prismaIDB {
  provider   = "idb-client-generator"
  output     = "./prisma-idb"
  outboxSync = true    // ← one flag
  rootModel  = "User"
}
  • Outbox pattern — mutations queue locally, push reliably with retry and batching
  • Ownership DAG — authorization is structural, every record traces back to its owner
  • Conflict resolution — server-authoritative changelog materialization on pull

Prisma 8 IDB quick start

Implements the Prisma 8 driver + adapter + target architecture for IndexedDB. Runtime queries use a bundled contract space; the CLI emits the contract and migration artifacts at build time.

pnpm add @prisma-idb/client-idb @prisma/orm-toolchain
pnpm add -D prisma@latest @prisma/cli-engine @prisma/orm-framework \
  @prisma-idb/family-idb @prisma-idb/target-idb \
  @prisma-idb/adapter-idb @prisma-idb/driver-idb

The usual flow is pnpm exec prisma-idb contract emit, pnpm exec prisma-idb migration plan, pnpm exec prisma-idb migration contract-space, then createAutoMigratingIdbClient({ contractSpace, dbName }) in browser code. See the Prisma 8 IDB documentation for full setup.

Resources

Contributing

Contributions welcome. See CONTRIBUTING.md.

Security

See SECURITY.md for reporting vulnerabilities.

License

MIT. See LICENSE.

Disclaimer

Prisma is a trademark of Prisma. Prisma IDB is an independent open-source project, not affiliated with or endorsed by Prisma.

About

The simplicity and features of the Prisma ORM, emulated in IndexedDB. Perfect for web apps needing structured local storage!

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

20 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages