I keep a small note when learning a new tool.
Not a full guide. Not polished documentation.
Just the syntax I actually use.
After a few projects with Supabase, I noticed the same pattern. I kept opening the docs, searching for the same things:
- How to insert a row
- How to query data
- How to update something
- How to call an RPC
So I wrote a small “quick syntax sheet”.
This is the version I wish I had when starting.
Supabase is simple once you learn the core pattern.
Almost everything follows this shape:
supabase
.from("table")
.operation(...)
If you remember that, the rest becomes predictable.
Setup
Create a client first.
import { createClient } from "@supabase/supabase-js"
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
)
That’s it.
Now every database call starts with supabase.
Select (Read Data)
The most common query.
const { data, error } = await supabase
.from("posts")
.select("*")
You’ll probably write this line hundreds of times.
Select specific columns
.select("id, title, created_at")
Example:
const { data } = await supabase
.from("posts")
.select("id, title")
Filter rows
.eq(column, value)
Example:
const { data } = await supabase
.from("posts")
.select("*")
.eq("author_id", user.id)
Other common filters:
.eq() equal
.neq() not equal
.gt() greater than
.lt() less than
.like() pattern match
Get one row
.single()
Example:
const { data } = await supabase
.from("posts")
.select("*")
.eq("id", postId)
.single()
Insert (Create Data)
Insert is straightforward.
const { data, error } = await supabase
.from("posts")
.insert({
title: "\"My post\","
content: "Hello world"
})
Multiple rows:
.insert([
{ title: "\"Post 1\" },"
{ title: "\"Post 2\" }"
])
Return inserted data
Add .select().
const { data } = await supabase
.from("posts")
.insert({ title: "\"Hello\" })"
.select()
Useful when you need the new id.
Update
Update rows with a filter.
const { data, error } = await supabase
.from("posts")
.update({ title: "\"Updated title\" })"
.eq("id", postId)
Without a filter, it updates every row.
That’s a mistake most people make once.
Delete
Delete also requires a filter.
await supabase
.from("posts")
.delete()
.eq("id", postId)
Again, no filter means deleting everything.
Ordering
Sort results.
.order("created_at", { ascending: false })
Example:
const { data } = await supabase
.from("posts")
.select("*")
.order("created_at", { ascending: false })
Limit
Limit rows returned.
.limit(10)
Example:
const { data } = await supabase
.from("posts")
.select("*")
.limit(10)
Pagination
Use .range().
.range(0, 9)
Example:
const { data } = await supabase
.from("posts")
.select("*")
.range(0, 9)
This returns rows 0–9.
Joins
Supabase uses PostgREST syntax.
Example:
const { data } = await supabase
.from("posts")
.select("*, profiles(username)")
This joins the profiles table.
Example result:
post
└ profile.username
Auth (Quick Syntax)
Get the current user:
const { data } = await supabase.auth.getUser()
Sign in:
await supabase.auth.signInWithPassword({
email,
password
})
Sign up:
await supabase.auth.signUp({
email,
password
})
Sign out:
await supabase.auth.signOut()
Storage
Upload a file.
await supabase.storage
.from("avatars")
.upload("user.png", file)
Get public URL:
supabase.storage
.from("avatars")
.getPublicUrl("user.png")
RPC (Calling Database Functions)
If you define a Postgres function, call it like this:
const { data } = await supabase
.rpc("get_popular_posts")
With parameters:
.rpc("get_posts_by_user", {
user_id: userId
})
The Pattern Behind Everything
After using Supabase for a while, you notice something simple.
Almost every query follows the same structure.
supabase
.from(table)
.action()
.filter()
.modifier()
Examples:
.from().select()
.from().insert()
.from().update()
.from().delete()
Once that clicks, the API feels predictable.
What I Actually Remember
When working quickly, I don’t remember the whole API.
I remember a few patterns:
.from("table").select("*").insert({}).update({}).eq().delete().eq().order().limit()
Everything else can be looked up.
A Small Lesson About Tools
Most tools feel complex at first.
But good tools have a small core idea.
For Supabase, it’s this:
Pick a table.
Choose an operation.
Add filters.
That’s most of the API.
Once you see the pattern, the documentation becomes easier to navigate.
Read on my site: https://kimkorngmao.com/notes/supabase-quick-docs
Top comments (0)