From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Updating records with Prisma

Updating records with Prisma

Alright, now let's implement the edit product functionality as well, for which we need to update the records. Now to update a row, we have the update and updateMany method. As you must have derived by the name that update is used to edit single row and updateMany is used to update multiple rows at once. Let's see the update method first. The syntax is similar to the other methods that we have seen till now. You call it by saying db.TableName.Update and pass the objects where you can define the conditions to select specific records and the data property where you have the updated data. Now let's practically implement it. I will go to the page.js of edit product folder and here we have the action for editing product data. So, I will configure the update method but before that, we will make some changes to the structure as well. Starting with the id, I will take a constant const pid is equal to parseInt in the brackets, I will say params.id and then to fetch the product detail, we will…

Contents