Firebase Alternative That Gives You Postgres
Supabase gives you a full Postgres database with instant REST and GraphQL APIs. Free tier includes 500MB storage, 2GB bandwidth, and 50K monthly active users.
Setup
- Create a project at supabase.com
- Copy your project URL and anon key
import { createClient } from "@supabase/supabase-js";
const supabase = createClient(
"https://your-project.supabase.co",
"your-anon-key"
);
Insert Data
const { data, error } = await supabase
.from("users")
.insert([{ name: "John", email: "john@example.com", role: "admin" }]);
if (error) console.error(error);
else console.log("Inserted:", data);
Query Data
// Simple select
const { data: users } = await supabase
.from("users")
.select("*")
.eq("role", "admin")
.order("created_at", { ascending: false })
.limit(10);
// With relationships (automatic JOINs)
const { data: posts } = await supabase
.from("posts")
.select("title, content, users(name, email)")
.eq("published", true);
Real-time Subscriptions
const channel = supabase
.channel("db-changes")
.on("postgres_changes",
{ event: "INSERT", schema: "public", table: "messages" },
(payload) => {
console.log("New message:", payload.new);
}
)
.subscribe();
Authentication (Built-in)
// Sign up
const { data, error } = await supabase.auth.signUp({
email: "user@example.com",
password: "secure_password"
});
// Sign in
const { data: session } = await supabase.auth.signInWithPassword({
email: "user@example.com",
password: "secure_password"
});
// OAuth (Google, GitHub, etc.)
const { data: oauth } = await supabase.auth.signInWithOAuth({
provider: "github"
});
File Storage
// Upload
const { data, error } = await supabase.storage
.from("avatars")
.upload("user1/avatar.png", file);
// Get public URL
const { data: url } = supabase.storage
.from("avatars")
.getPublicUrl("user1/avatar.png");
Python Client
from supabase import create_client
supabase = create_client("https://your-project.supabase.co", "your-anon-key")
# Query
result = supabase.table("users").select("*").eq("role", "admin").execute()
print(result.data)
# Insert
supabase.table("users").insert({"name": "Jane", "email": "jane@example.com"}).execute()
Supabase vs Firebase vs PlanetScale
| Feature | Supabase | Firebase | PlanetScale |
|---|---|---|---|
| Database | Postgres | NoSQL | MySQL |
| Free storage | 500MB | 1GB | 5GB |
| Auth | Built-in | Built-in | No |
| Real-time | Yes | Yes | No |
| SQL support | Full | No | Full |
| Self-host | Yes | No | No |
| Edge functions | Yes | Yes | No |
More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
Top comments (0)