⚡ Supabase + supabase-js CRUD Cheat Sheet
When building apps with Expo (React Native) and Supabase, you rarely write raw SQL. Instead, you use the @supabase/supabase-js client which feels like a clean, modern ORM.
Below is your quick reference for all CRUD operations, real-time updates, and auth flows. Copy, paste, and ship faster 🚀
🟢 Create
const { data, error } = await supabase
.from("todos")
.insert([{ title: "Learn Supabase", is_complete: false }])
.select();
🔵 Read
// Get all rows
const { data, error } = await supabase
.from("todos")
.select("*");
// Order results
const { data } = await supabase
.from("todos")
.select("*")
.order("inserted_at", { ascending: false });
// Filter rows
const { data } = await supabase
.from("todos")
.select("*")
.eq("is_complete", false);
🟡 Update
const { data, error } = await supabase
.from("todos")
.update({ is_complete: true })
.eq("id", 1)
.select();
🔴 Delete
const { error } = await supabase
.from("todos")
.delete()
.eq("id", 1);
📡 Real-time
const channel = supabase
.channel("todos-changes")
.on(
"postgres_changes",
{ event: "*", schema: "public", table: "todos" },
(payload) => console.log("Change:", payload)
)
.subscribe();
// Cleanup
supabase.removeChannel(channel);
🔐 Auth
// Sign up
await supabase.auth.signUp({
email: "test@example.com",
password: "password123",
});
// Sign in
await supabase.auth.signInWithPassword({
email: "test@example.com",
password: "password123",
});
// Get user
const { data: { user } } = await supabase.auth.getUser();
// Sign out
await supabase.auth.signOut();
✅ Every query gives you { data, error } — always check both.
🔑 Use Row Level Security + policies to control user access.
🚀 With this cheat sheet, you’re ready to build full-stack apps with Expo + Supabase, no extra backend required.
Happy coding! 💻✨
Comments
Post a Comment