0
Challenge · 63The Data API & Your Next.js App
Querying: filters, embeds, pagination, count
Queriesused in ~100% of apps
Every SQL idea you own from tiers 1–4 — WHERE, NULL, JOIN, ORDER BY, LIMIT, COUNT — has to come back out through one JavaScript surface: supabase.from(...).select(...). The method names don't map onto the SQL 1:1, and three of the mismatches are exactly where juniors lose a day: a null check that matches nothing, a filter on an embedded table that doesn't do what a WHERE would do, and a pagination cap that quietly returns 1000 rows less than the table actually holds.
Core idea. The query builder is a thin, chainable translator: .select('col, related(col)') becomes a SELECT with a JOIN PostgREST infers from your foreign keys, .eq()/.gt()/.is() etc. become WHERE, .order()/.range() become ORDER BY/LIMIT/OFFSET, and { count } asks Postgres for a row count using one of three cost tradeoffs. Every one of these compiles to real SQL running through the RLS you already wrote — nothing here is a new authorization layer, only a new spelling for the SQL you already know.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
Live demointeractive
Real Postgres · in your browseridle
This is the SQL shape of
supabase.from('posts').select('id, title, author:profiles(username), comments(id, body)').eq('is_public', true).order('created_at', { ascending: false }). Run it. Both public posts come back, including bob's post 3 — with exactly one comment, not duplicated rows for anything else. Now change p.is_public = true to p.id = 1 and imagine a THIRD table embedded the same way: what would you expect for a post with zero likes-table rows?Cmd/Ctrl + Enter
↑ play a little first, then dig in