Update
Update to records can be done with the following methods:
update- Update a single, unique record.updateMany- Update multiple records that match the query criteria.updateManyAndReturn- Similar toupdateMany, but returns the updated recordsupsert- Update a single, unique record, or create it if it does not exist.
Updating scalar fields
- Interactive Sample
- Plain Code
Click here to pop out if the embed doesn't load an interactive terminal.
scalar.ts
Loading...
In additional to the standard way of updating fields, list fields support the following operators:
push: Append a value or a list of values to the end of the list.set: Replace the entire list with a new list (equivalent to setting the field directly).
await db.post.update({
where: { id: '1' },
data: {
topics: { push: 'webdev'},
},
});
await db.post.update({
where: { id: '1' },
data: {
topics: { set: ['orm', 'typescript'] },
},
});
Manipulating relations
THe update and upsert methods are very powerful in that they allow you to freely manipulate relations. You can create, connect, disconnect, update, and delete relations in a single operation. You can also reach deeply into indirect relations.
updateMany and updateManyAndReturn only support updating scalar fields.
- Interactive Sample
- Plain Code
Click here to pop out if the embed doesn't load an interactive terminal.
relation.ts
Loading...