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.

Fetching data with Prisma

Fetching data with Prisma

Alright, now let's render the products from the newly created database. So in the page.js of the app folder, we have the code for rendering the products cards. Now we will render the products later on. First, let's discover the various methods offered for data fetching in Prisma. I will take a constant, will say const pdata is equal to await db.products. And there are total five methods we can use. They are findMany, findFirst, findFirstOrThrow, findUnique and findUniqueOrThrow. Let's try the findMany method. I will say dot findMany and put a console log to display the pdata. Let's save and check the output. I'll open the console and there we have all the rows from the products table. Next we will try the find first method. I'll call it by saying products.findfirst along with this db. And let's check the output. So there we have the first record of the table displayed and we can check it from the database as well. Now to fetch any specific row, we have the findUnique method. Do note…

Contents