DEV Community

Cover image for CRUD Functions using Prisma, Nextjs, and Supabase(Postgress database)
Next Dev
Next Dev

Posted on

CRUD Functions using Prisma, Nextjs, and Supabase(Postgress database)

Welcome friends to this new blog post where I will teach you how to use CRUD functions using Prisma(ORM tool) with the help of Nextjs (API folder).

First, you have to setup Prisma in your Nextjs app 👇
Get Started with Prisma and Nextjs with Supabase (Postgress Database)

So, let’s begin

First, you need to install 2 packages

yarn add react-hot-toast swr
Enter fullscreen mode Exit fullscreen mode

😁Create Schema



Then write this command

prisma migrate dev
Enter fullscreen mode Exit fullscreen mode

If you don’t have any GUI tool for managing your data in the database. Then you can write this command

prisma studio
Enter fullscreen mode Exit fullscreen mode

That will open up a website at localhost:5555, by which you can manage your data quickly.

✍️Create Function

First, you need to create a form.



Then you need to make an API ENDPOINT in your app.

To create that, make a file named — profiles.ts in your API folder in the pages folder.

Then write this code 👇


//@ts-ignore in 18th line helps to ignore the type error.

Now you can try the **create **command.

📖Read Function


Then go to your profiles.ts in API folder.

Now you can get the data that you created:

📝Update Function


Then go to your profiles.ts in api folder.

Now, you can see that your entry.name has been changed to ‘Taranpreet Singh’.

⛔Delete function


Now you can go to api.tsx in your api folder.

Now you can test the button.

If you encounter any error, then observe your console logs.

😃Thanks for reading.

If you understand Hindi, you can watch this tutorial 👇
https://youtu.be/NiCQ4KIi6VU

You can join my discord channel here 👇
Join the Next Dev's server Discord Server!

Top comments (0)