CRUD functions in supabase šŸ‘‹

CRUD functions in supabase šŸ‘‹

Ā·

2 min read

Welcome guys to this 2nd blog for supabase and nextjs integration. In this blog, I will be telling you how to create, read, update, and delete data in a subbase with the help of next js.

šŸ¤” If you donā€™t know how to set up supabase then you can read this blog šŸ‘‡ How to connect Supabase and Nextjs

Crud function has three parts: Create, read, update, delete

šŸ“Create

You can go to the index.js file in your next app. Then create one more folder named ā€˜componentsā€™ in which make a new file: ā€˜Card.jsxā€™

For creating rows in supabase. First, we need to make a table in supabase

There will be three columns in the posts table:

  1. id : primary key, type: int

  2. created_at: type: timestamp, default: now()

  3. title: type: text

Then, at last, click on the save button.

Now, the coding begins šŸ« 

In the Card.jsx, write the following code: %[gist.github.com/studywithdesign/34ea01affa2..

But what if you want to create data in bulk:

You can add new dicts in array
[
{title: title}, {title: title} //šŸ¤” we have made one more title dict in the array
]

Now, comes the reading part:

Go to index.js file and then write this code. %[ gist gist.github.com/studywithdesign/1b9832810fd..

āœļøUpdate

In supabase update function. We need to pass two have two things

  1. The data that we want to change

  2. The id or any column for choosing which row to update

    Now comes the last part.

ā›”Delete

šŸ‘‹So, by this our code ends. Letā€™s meet for the next project.

Did you find this article valuable?

Support Next Dev's Blog by becoming a sponsor. Any amount is appreciated!

Ā