Learn how to delete records in Supabase with our step-by-step guide—from setting up your project and database table to installing the client and executing delete commands.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up a Supabase Project
To get started with deleting records, you first need to have a Supabase project set up. If you haven't already done this, follow these steps to create a new project on Supabase:
Step 2: Navigate to the Supabase Dashboard
Once your project is up and running, navigate to the Supabase Dashboard for your project:
This will take you to the main dashboard for your project.
Step 3: Set Up Database Table
For deleting records, you need to have a database table in your project:
users
with columns id
, name
, and email
.
Step 4: Install Supabase Client in Your Application
To interact with your Supabase database, you'll use the Supabase client. Install the client in your application:
npm install @supabase/supabase-js
Step 5: Initialize Supabase Client
Initialize the Supabase client in your application code with your project's credentials:
import { createClient } from '@supabase/supabase-js'
// Replace with your Supabase API URL and Key
const supabaseUrl = 'https://xyzcompany.supabase.co'
const supabaseKey = 'public-anonymous-key'
const supabase = createClient(supabaseUrl, supabaseKey)
Step 6: Delete Records from Supabase Table
To delete records from a table, use the Supabase client to interact with your database:
async function deleteUser(userId) {
const { data, error } = await supabase
.from('users')
.delete()
.eq('id', userId)
if (error) {
console.error('Error deleting user:', error)
} else {
console.log('User deleted:', data)
}
}
// Call the function with a specific user id
deleteUser(123)
Step 7: Verify Deletion via Supabase Dashboard
Finally, verify that the record has been deleted:
users
table.id
has been removed.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.