Writing data
Create, update, upsert and delete records. Every write returns the record as it is after the write, typed from your contract.
Create
const user = await db.user.create({ data: { email: "lin@example.com", name: "Lin" } });Create many
const { count } = await db.post.createMany({
data: [{ title: "One" }, { title: "Two" }],
skipDuplicates: true,
});Update
await db.post.where({ id: postId }).update({ data: { published: true } });update on a where that matches several records updates all of them and returns the count. Use .first().update() to update exactly one.
Upsert
await db.user.upsert({
where: { email: "lin@example.com" },
create: { email: "lin@example.com", name: "Lin" },
update: { name: "Lin" },
});Delete
Method | Matches | Returns |
|---|---|---|
| exactly one, or throws | the deleted record |
| any number |
|
Updated
Was this page helpful?