Prisma IDB FaviconPrisma IDB
CRUD Operations

Introduction to CRUD

Complete guide to creating, reading, updating, and deleting data

The Prisma IDB client provides a comprehensive CRUD API that mirrors Prisma Client, making it easy to work with IndexedDB.

Overview

All CRUD operations are asynchronous and return typed results matching your Prisma schema. They support:

  • Filtering: Query with where clauses
  • Sorting: Order results with orderBy
  • Pagination: Use skip and take
  • Selection: Include/exclude fields with select and include
  • Transactions: Execute atomically across multiple stores
  • Events: Mutations emit events for reactive updates
  • Outbox: Changes queue for server sync (when enabled)

Operations

Create

Read

Update

Delete

Upsert

Common Options

All mutation operations (create, update, delete, upsert) accept options:

{
  tx?: IDBPTransaction,    // Use existing transaction
  silent?: boolean,        // Don't emit events (default: false)
  addToOutbox?: boolean,   // Queue for sync (default: true if sync enabled)
}

All read operations accept:

{
  tx?: IDBPTransaction,    // Use existing transaction (read-only)
}

Examples

Simple Create and Read

// Create
const user = await client.user.create({
  data: { name: "Alice", email: "alice@example.com" },
});

// Read
const users = await client.user.findMany();
const alice = await client.user.findUnique({ where: { email: "alice@example.com" } });

With Relations

const user = await client.user.create({
  data: {
    name: "Alice",
    profile: { create: { bio: "Hi!" } },
  },
  include: { profile: true },
});

Filtering and Pagination

const todos = await client.todo.findMany({
  where: { done: false, priority: { gt: 5 } },
  orderBy: { createdAt: "desc" },
  skip: 0,
  take: 10,
});

Aggregations

const stats = await client.todo.aggregate({
  _count: true,
  _avg: { priority: true },
  _max: { priority: true },
});

console.log(`${stats._count} todos, avg priority: ${stats._avg.priority}`);

See Also

On this page