57
loading...
This website collects cookies to deliver better user experience
const updatedAuthor = await prisma.author.update({
data: {
firstName: "Updated first name",
lastName: "Updated last name",
},
where: {
id: authors[0].id,
},
});
console.log({ updatedAuthor });
prisma.[entity].update
, not so different from the insert and the delete, obviously the update method updates an existing row. And another thing, if the update method doesn't find the record, it throws an exception that you have to handle in your code.{
updatedAuthor: {
id: 3,
firstName: 'Updated first name',
lastName: 'Updated last name'
}
}
increment
, decrement
, multiply
or divide
a field in a atomic update operation. To do this Prisma exposes us these commands in the type IntFieldUpdateOperationsInput
export type IntFieldUpdateOperationsInput = {
set?: number
increment?: number
decrement?: number
multiply?: number
divide?: number
}
const updatedAuthor = await prisma.author.update({
data: {
id: {
increment: 1
}
},
where: {
id: authors[0].id,
},
});
where
seen in the deleteMany operation with the features explained above, so it's obvious to understand that this operation allows you to update many records, using a complex filter.