Schema & Config
Which Prisma schema features IndexedDB supports, and what prisma.config.ts contains
This page lists what a Prisma schema can contain when it targets IndexedDB, and what each field in prisma.config.ts does. For a first setup, follow the Quick Start instead.
For PSL attributes alongside the TypeScript DSL, see Contract Authoring.
Editor support
For Prisma VS Code extension hints, put // use prisma-8 on the first line of each Prisma 8 schema, before other comments or declarations:
// use prisma-8
model Todo {
id String @id
title String
}This directive selects the Prisma 8 language server. Without it, the extension uses the legacy language server, which does not read IDB's authoring metadata. With the IDB family configured, the Prisma 8 server provides scalar type completion and descriptions, attribute signatures and documentation (including @idb.exclude and @@idb.exclude), and schema diagnostics from the IDB validator.
For installation, monorepo configuration, and missing hints, follow Editor Setup.
Scalar types
| Prisma type | JavaScript value | Notes |
|---|---|---|
String | string | |
Int | number | |
Float | number | |
Boolean | boolean | Can't be a key or indexed. See Indexes. |
DateTime | Date | Compared and sorted by time, not by object identity. |
BigInt | bigint | Can't be a key or indexed. |
Decimal | string | Stored as text; compared and sorted numerically. |
Json | any JSON value | Can't be a key or indexed. |
Bytes | Uint8Array | Compared and sorted byte by byte. |
Add ? to make a field optional. Its value is then null when it isn't set.
Decimal values stay as the strings you supply. Accepted forms include "-12.50", ".5" and "1.25e3". Empty strings, whitespace, hexadecimal values, NaN and infinities are invalid. Creates and updates reject invalid Decimal values. Numeric filter operands must also be valid decimal text, even when the query would return no rows. A numeric comparison that encounters invalid text in existing records throws; repair those records before filtering or sorting them.
Decimal equality, membership, range filters and orderBy compare exact numeric values without converting them to JavaScript numbers. For example, "10", "10.00" and "1e1" compare equal. Primary-key lookups and unique constraints use the same numeric equality, including in compound keys.
For a Decimal primary key stored as "10", findUnique("10.00") returns that row. Creating another row with key "1e1" fails with a unique constraint error. Updates, deletes and upserts also resolve equivalent Decimal key spellings. Updating a primary key from "10" to "10.00" keeps the stored spelling "10".
Numeric key checks run inside the write transaction. Mutations on models with Decimal primary or unique keys require a transaction-capable executor, such as the standard IndexedDB runtime. Decimal primary-key lookups read the physical key first, then scan for numeric aliases. The scan also detects conflicting rows from older databases, even after an exact hit. Decimal unique checks scan rows too; native string indexes cannot enforce numeric equality. Keys without Decimal fields retain their native lookup and uniqueness paths.
If older data contains several primary or unique keys for the same numeric value, identity operations throw IdbDecimalIdentityConflictError with code DECIMAL_IDENTITY_CONFLICT. Resolve those conflicting records before retrying. The client never selects or deletes a conflicting row automatically. Sync uses the same numeric identity for pending changes, staleness checks and rejected-write reconciliation. It preserves existing local key spellings and metadata references without changing the storage schema or wire format. This does not add compound-key support to the SQL sync server.
Models and stores
Each model becomes an IndexedDB object store. The store is named after the model with its first letter lowercased, so model TodoItem is stored in todoItem. The same name is the model's key on the client: db.orm.todoItem.
Use @@map to choose a different name:
model Todo {
id String @id
title String
@@map("todos")
}const todos = await db.orm.todos.all();Primary keys
Every model needs a primary key.
@idon one field, or@@id([a, b])for a compound key.- Key fields must be
String,Int,Float,DateTime,DecimalorBytes, the types IndexedDB can use as keys. - In a compound key, order matters:
@@id([a, b])and@@id([b, a])are different keys.findUnique()anddelete()take the values in the order you declared them. @default(autoincrement())is supported on a single-fieldIntkey, not on a compound key.
Indexes
| Attribute | Creates |
|---|---|
@unique | A unique index on one field. |
@@unique([a, b]) | A unique compound index. |
@@index([a]) | A non-unique index. |
@@index([a, b]) | A non-unique compound index. |
Pass name: to choose an index's name, for example @@index([userId], name: "byUser"). Without one, the name is the field names joined with _, plus _unique for a unique index. A field can't appear twice in one index.
Like keys, indexed fields must be String, Int, Float, DateTime, Decimal or Bytes. IndexedDB silently leaves other values out of an index, so contract emit rejects an index on a Boolean, BigInt or Json field.
Queries use an index automatically for supported equality filters on an indexed field. Decimal predicates and sorting run in memory because their stored strings have a different order from their numeric values. A query can still use a separate index to narrow candidates safely.
Defaults
| Attribute | Sets the field to |
|---|---|
@default("text"), @default(0), @default(true) | That literal value, on create. |
@default(now()) | The current time, on create. |
@default(uuid()) | A random UUID v4, on create. uuid(7) gives a UUID v7. |
@default(cuid()) | A CUID2, on create. |
@default(autoincrement()) | The next number, assigned by IndexedDB. Single Int keys only. |
@updatedAt | The current time, on create and on every update. |
A default only applies when the field is left out. It also counts as setting the field: a foreign key filled in by a default is checked like one you set yourself.
Relations
Declare relations the usual way, with @relation(fields: [...], references: [...]) on the side that holds the foreign key.
model Todo {
id String @id
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}- One-to-many, many-to-one and one-to-one relations are supported. Many-to-many relations aren't; use an explicit join model.
- Compound foreign keys are supported:
@relation(fields: [orgId, userId], references: [orgId, id]). onDeleteandonUpdateacceptCascade,SetNull,SetDefault,RestrictandNoAction. Both default toRestrict.NoActionbehaves likeRestrict.
IndexedDB has no foreign keys of its own, so the client enforces them. See Foreign keys and referential actions for exactly what it checks.
Server-only fields and models
When you sync with a server, mark fields and models that must never reach the browser with @idb.exclude (a field) or @@idb.exclude (a model). The browser's contract leaves them out when your config sets projection: "client":
contract: prismaIdbContract("src/prisma/schema.prisma", { projection: "client" }),Client Contracts explains the rules, including what happens to a relation that points at an excluded model.
Config
prisma.config.ts wraps an orm section built with defineConfig from @prisma-idb/family-idb/config-types. The Quick Start shows a complete file.
| Field | Value for IndexedDB | What it does |
|---|---|---|
family | @prisma-idb/family-idb/control | The database family. |
target | @prisma-idb/target-idb/control | The target within the family. Carries the migration planner. |
adapter | @prisma-idb/adapter-idb/control | Maps Prisma types to how IndexedDB stores them. |
driver | @prisma-idb/driver-idb/control | Required by the framework. No CLI command can reach a browser database, so this is a stub. |
db.connection | Any string, such as ":memory:" | Required by the framework, unused. The database name is chosen in the browser, with dbName. |
contract | prismaIdbContract("path/to/schema.prisma", { projection }) | The schema to read. prisma-idb contract emit writes contract.json, contract.d.ts, and contract.runtime.ts next to it. |
migrations.dir | "migrations" | Where prisma-idb migration plan writes migration packages. |
Both prisma and prisma-idb read this file, so neither needs --contract or --migrations-dir flags. Pass --config <path> if the file isn't in the project root.