Database
Database guide for your application.
Setup
In the authentication section you already learned how to set up a Supabase database for your application. Here you will learn how to use it in your application.
Using Supabase Database
All the implementation is done using the Supabase JavaScript client, which provides a simple and intuitive API for interacting with your database.
You can use both implementations from src/lib/supabase/client.ts
and src/lib/supabase/server.ts
for client and server components.
Here's some examples of how to use the client and server:
// Client
const supabase = await createClient();
const { data, error } = await supabase.auth.getUser();
// Server
const supabase = await createClient()
const { error } = await supabase.from('payments')
.insert({
sessionId: resultObj.id,
webhook: 'checkout.session.completed',
status: resultObj.status,
paymentStatus: resultObj.payment_status,
paymentMethodTypes: resultObj.payment_method_types,
paymentIntent: resultObj.payment_intent,
plan: plan,
invoiceId: resultObj.invoice,
env: process.env.ENV || 'DEV',
})
.select()
.single()