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.

Inserting data using create()

Inserting data using create()

In this lecture, we are going to perform the data insertion via Prisma. To perform insertion, the instance created using the Prisma client, which is the DB object, offers various methods like create, createMany, findMany, count, etc. All of them are used to perform a specific thread operation. Coming back to the data insertion, we will use the create method to insert data. The syntax is like this, we call it by saying db.tableName.create and it will take an object as argument and it should contain the data property which will have all the data to be inserted in an object literal. So in our case, the fields are name, price and image. So here, the object will be data and it will have name, price, image and respective values. Let's practically try this. At the moment, we have the SQLite database in the existing project. And the server action for adding data to the database is configured in the page.js of the add product folder. Let me open it. Here I will create another server action…

Contents