Store and query scalar lists
Declare scalar lists, update their elements, and migrate existing records.
Declare a list by adding [] to a scalar or enum type. For example:
model Note {
id String @id
tags String[] @default([])
}With TypeScript authoring, use fields: { id: "String", tags: "String[]" } and defaults: { tags: [] } in the model definition. Re-emit the contract and generate the migration and contract space, as described in Author a field change. Apply the generated migration before querying existing records.
Create a record with an array. Omit a list only when it declares a default:
await db.orm.note.create({ id: "n1", tags: ["draft"] });
await db.orm.note.create({ id: "n2" }); // stores tags: []Use an update callback to change an element. push accepts one element:
await db.orm.note.where({ id: "n1" }).update((u) => [u.tags.push("review")]);
await db.orm.note.where({ id: "n1" }).update((u) => [u.tags.addToSet("review")]);
await db.orm.note.where({ id: "n1" }).update((u) => [u.tags.pull("draft")]);
await db.orm.note.where({ id: "n1" }).update((u) => [u.tags.pop(-1)]);
await db.orm.note.where({ id: "n1" }).update((u) => [u.tags.set([])]);Use a plain patch to replace the entire array: .update({ tags: ["published"] }). The same operations work in updateAll, updateCount, and the update arm of upsert. Specify at most one operation per field in a callback.
Compare a complete list with eq. Array order matters:
const drafts = await db.orm.note.where((m) => m.tags.eq(["draft"])).all();
const empty = await db.orm.note.where((m) => m.tags.eq([])).all();
const ordered = await db.orm.note.orderBy({ tags: "asc" }).all();Read the scalar-list reference for supported types and operators. Read why missing lists stay missing before migrating legacy data.