A Prisma generator that creates a familiar, type-safe client for IndexedDB with optional bidirectional synchronization to a remote server. Define your data model once in Prisma schema, and get both a local-first IndexedDB client and a complete sync engine built for conflict resolution and authorization.
π Documentation β’ π Live Demo β’ π¦ npm Package β’ ποΈ GitHub Repository
- Prisma-like API: Use the syntax you already know. CRUD operations feel exactly like Prisma Client.
- Type Safety: Fully typed operations generated directly from your Prisma schema.
- Local-First: All data lives in IndexedDB. Works offline, syncs when ready.
- Optional Sync Engine: Bidirectional sync with authoritative DAG-based conflict resolution.
- Authorization & Ownership: Built-in ownership invariants ensure users can only modify their data.
- Outbox Pattern: Reliable push operations with automatic retry and batch support.
- Changelog Materialization: Efficient pull operations that materialize server state for clients.
Get Prisma IDB up and running in just a few steps.
pnpm add idb
pnpm add @prisma-idb/idb-client-generator --save-devOptionally, for auto-generated IDs:
pnpm add @paralleldrive/cuid2 uuidAdd the generator to your prisma/schema.prisma:
generator prismaIDB {
provider = "idb-client-generator"
output = "./prisma-idb"
// Optional: Enable sync engine
outboxSync = true
rootModel = "User"
exclude = ["Changelog", "Session"]
}model User {
id String @id @default(cuid()) // Client-generated IDs required for sync
name String
email String @unique
todos Todo[]
}
model Todo {
id String @id @default(cuid())
title String
done Boolean @default(false)
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}Generate the client:
pnpm exec prisma generateUse it in your code:
import { PrismaIDBClient } from "./prisma-idb";
const client = await PrismaIDBClient.createClient();
// Create
await client.user.create({
data: { name: "Alice", email: "alice@example.com" }
});
// Read
const todos = await client.todo.findMany({
where: { userId: userId, done: false }
});
// Update
await client.todo.update({
where: { id: todoId },
data: { done: true }
});
// Delete
await client.todo.delete({
where: { id: todoId }
});pnpm add @prisma-idb/idb-client-generator --save-devThis project uses pnpm workspaces and includes a devcontainer configuration for a consistent development environment.
- Open the project in VS Code
- Install the "Dev Containers" extension if you haven't already
- Click "Reopen in Container" when prompted, or use the command palette:
Dev Containers: Reopen in Container - The container will automatically install dependencies using pnpm
If you prefer to develop locally:
- Install pnpm:
corepack enable(Node.js 16.13+) ornpm install -g pnpm - Install dependencies:
pnpm install - Run development server:
pnpm dev - Run tests:
pnpm test
The API mimics Prisma Client's API for ease of use:
Insert a new record:
idbClient.modelName.create({
data: {
field: value,
},
});Retrieve all records:
idbClient.modelName.findMany();Retrieve a single record by unique key:
idbClient.modelName.findUnique({
where: { key: value },
});Update a record:
idbClient.modelName.update({
where: { key: value },
data: { key: newValue },
});Delete a record:
idbClient.modelName.delete({
where: { key: value },
});- π Full Documentation - Complete API reference and guides
- π Live Kanban Demo - See the sync engine in action
- π¦ npm Package - Install from npm
- ποΈ GitHub Repository - Source code and issue tracking
- Example App Source - Real-world implementation reference
We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to contribute to this project.
If you discover a security vulnerability, please follow our SECURITY.md guidelines on reporting issues responsibly.
This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for more details.
Prisma is a trademark of Prisma.
Prisma IDB is an independent open-source project and is not affiliated with, endorsed by, or sponsored by Prisma. This library is a generator built on top of Prisma to extend its functionality.