Note: This is mock/placeholder content for demonstration purposes.
Efficiently query and filter data using Supabase's query builder.
const { data, error } = await client
.from('projects')
.select('*');
const { data, error } = await client
.from('projects')
.select('id, name, created_at');
const { data, error } = await client
.from('projects')
.select(`
id,
name,
account:accounts(id, name),
tasks(id, title, completed)
`);
const { data } = await client
.from('projects')
.select('*')
.eq('status', 'active');
const { data } = await client
.from('projects')
.select('*')
.neq('status', 'deleted');
const { data } = await client
.from('projects')
.select('*')
.gt('created_at', '2024-01-01')
.lt('budget', 10000);
const { data } = await client
.from('projects')
.select('*')
.in('status', ['active', 'pending']);
const { data } = await client
.from('projects')
.select('*')
.like('name', '%website%');
const { data } = await client
.from('projects')
.select('*')
.textSearch('description', 'design & development');
const { data } = await client
.from('projects')
.select('*')
.order('created_at', { ascending: false });
const { data } = await client
.from('projects')
.select('*')
.order('status')
.order('created_at', { ascending: false });
const { data } = await client
.from('projects')
.select('*')
.limit(10);
const page = 2;
const pageSize = 10;
const from = (page - 1) * pageSize;
const to = from + pageSize - 1;
const { data, count } = await client
.from('projects')
.select('*', { count: 'exact' })
.range(from, to);
const { count } = await client
.from('projects')
.select('*', { count: 'exact', head: true });
const { count } = await client
.from('projects')
.select('*', { count: 'exact', head: true })
.eq('status', 'active');
const { data } = await client
.from('projects')
.select('*')
.eq('account_id', accountId)
.eq('status', 'active')
.gte('created_at', startDate)
.lte('created_at', endDate)
.order('created_at', { ascending: false })
.limit(20);
const { data } = await client
.from('projects')
.select('*')
.or('status.eq.active,status.eq.pending');
const { data } = await client
.from('projects')
.select('*')
.or('and(status.eq.active,priority.eq.high),status.eq.urgent');
const { data } = await client
.from('projects')
.select(`
*,
account:accounts!inner(
id,
name
)
`)
.eq('account.name', 'Acme Corp');
const { data } = await client
.from('projects')
.select(`
*,
tasks(*)
`);
const { data } = await client
.from('projects')
.select('*')
.is('completed_at', null);
const { data} = await client
.from('projects')
.select('*')
.not('completed_at', 'is', null);
const { data, error } = await client
.from('projects')
.insert({
name: 'New Project',
account_id: accountId,
status: 'active',
})
.select()
.single();
const { data, error } = await client
.from('projects')
.insert([
{ name: 'Project 1', account_id: accountId },
{ name: 'Project 2', account_id: accountId },
])
.select();
const { data, error } = await client
.from('projects')
.update({ status: 'completed' })
.eq('id', projectId)
.select()
.single();
const { data, error } = await client
.from('projects')
.update({ status: 'archived' })
.eq('account_id', accountId)
.lt('updated_at', oldDate);
const { error } = await client
.from('projects')
.delete()
.eq('id', projectId);
const { error } = await client
.from('projects')
.delete()
.in('id', projectIds);
const { data, error } = await client
.from('projects')
.upsert({
id: projectId,
name: 'Updated Name',
status: 'active',
})
.select()
.single();
const { data, error } = await client
.rpc('get_user_projects', {
user_id: userId,
});
const { data, error } = await client
.rpc('search_projects', {
search_term: 'design',
account_ids: [1, 2, 3],
min_budget: 5000,
});
const { data, error } = await client
.from('projects')
.select('*');
if (error) {
console.error('Error fetching projects:', error.message);
throw error;
}
return data;
import { PostgrestError } from '@supabase/supabase-js';
function handleDatabaseError(error: PostgrestError) {
switch (error.code) {
case '23505': // unique_violation
throw new Error('A project with this name already exists');
case '23503': // foreign_key_violation
throw new Error('Invalid account reference');
default:
throw new Error('Database error: ' + error.message);
}
}
import { Database } from '~/types/database.types';
type Project = Database['public']['Tables']['projects']['Row'];
type ProjectInsert = Database['public']['Tables']['projects']['Insert'];
type ProjectUpdate = Database['public']['Tables']['projects']['Update'];
const { data } = await client
.from('projects')
.select('*')
.returns<Project[]>();
select('*') unnecessarilyEXPLAIN ANALYZE in SQL