Prisma IDB FaviconPrisma IDB

API

Every method on a model accessor

Each model has an accessor on db.orm, such as db.orm.todo. You build a query by chaining methods, then run it with a terminal method:

const todos = await db.orm.todo.where({ done: false }).orderBy({ title: "asc" }).take(10).all();

Chaining returns a new accessor and never changes the one you started from, so you can reuse a partial query.

Package entry points

Import idbOrm, accessor types, and filter helpers from @prisma-idb/client-idb/orm. For nested writes, the client supplies the relation mutator to your callback; see Write related rows.

Import createAutoMigratingIdbClient or createManagedAutoIdbClient from @prisma-idb/client-idb/client-auto to apply migrations when opening the database.

Chaining methods

MethodDoesDetails
where(filter)Keeps rows that match. Calling it again adds another condition (AND).Filtering
orderBy(spec)Sorts the results.Sorting
skip(n), take(n)Skips n rows, or returns at most n.Sorting
include(relation, refine?)Loads a related model into each row.Relations
select(...fields)Returns only these scalar fields.Select
groupBy(...fields)Groups rows for aggregate().Group by

Reading

MethodReturns
all()Every matching row. Await it, or iterate it with for await.
first()The first matching row, or null.
findUnique(key)The row with this primary key, or null. Ignores where, include and select.
count()The number of matching rows, after skip and take.
aggregate(callback)Counts, sums, averages, minimums and maximums.

Writing

MethodDoesReturns
create(data)Inserts a row. Fails if the primary key exists.The new row.
createAll(data[])Inserts rows in one transaction.The new rows.
createCount(data[])Same as createAll.How many rows were inserted.
update(patch)Updates the first matching row.The updated row, or null.
updateAll(patch)Updates every matching row.The updated rows.
updateCount(patch)Same as updateAll.How many rows were updated.
upsert(args)Updates the row matching where, or creates one.The row.
delete(key)Deletes the row with this primary key. Ignores where.Nothing.
deleteAll()Deletes every matching row.The deleted rows.
deleteCount()Same as deleteAll.How many rows were deleted.

Every write runs in one IndexedDB transaction, including the foreign-key checks and referential actions it triggers. See Writing.

On this page