Supabase, Neon and many hosts are all PostgreSQL. Learn the basics once and you can use any of them, including behind your own API.
Core concepts
- Tables, keys and types: Use
uuidorbigintprimary keys,timestamptzfor times, foreign keys for relationships andnot nullwherever data is required. — PostgreSQL docs - Indexes: Index columns you filter or join on, such as
user_id. Without them queries slow down as data grows. — PostgreSQL docs - Migrations: Store schema changes as ordered SQL files in git so every environment reaches the same schema. — Drizzle
- Never connect the app directly: A mobile app should not hold a database connection string. Put an API or edge function between the app and a managed Postgres such as Neon. — Neon docs
- Drizzle ORM: A typed TypeScript query builder that works on the server and keeps SQL close to the surface; good for agent-generated queries. — Drizzle
Concept videos
YouTube channels and searches for these topics. On a large screen they open in the reading panel next to the roadmap.
- PostgreSQL tutorials — YouTube search: PostgreSQL crash course
Explanation
API shape
Expose a few narrow endpoints (GET /items, POST /items) that check the signed-in user and run parameterised queries. Never accept raw SQL from the client.
Connection limits
Serverless functions can open many connections; use the host's pooled connection string.
What Is It?
PostgreSQL is a powerful open-source relational database used behind most serious apps.
Why Should I Care?
Knowing it lets you move between hosts and review the SQL your agent writes.
Real World Analogy
Postgres is a well-run warehouse: shelves (tables), barcodes (keys), an index at the door, and a manager (API) who decides who may fetch what.
Visual Mental Model
App -> HTTPS API (auth) -> pooled Postgres connection -> tablesSmallest Possible Example
create table public.todos (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references auth.users (id) on delete cascade,
title text not null,
done boolean not null default false,
created_at timestamptz not null default now()
);
create index todos_user_id_idx on public.todos (user_id);Common Mistakes
❌ Exposing a connection string in the app.
Anyone can extract it from the bundle.
❌ No indexes on foreign keys.
Queries slow down sharply with growth.
Build This Mini Project
Create a Neon database, a todos table, and a small API route that lists the signed-in user's todos with Drizzle.
Prompts for Cursor, Claude Code & Codex
Paste these into Cursor, Claude Code, Codex, or any coding agent. Replace the bracketed parts with your app details, and keep the agent in plan mode first so you review the approach before it edits files.
Drizzle schema and API
Create a Drizzle schema for [entities] on PostgreSQL with indexes, and an API route to list and create items scoped to the authenticated user. Use parameterised queries only, validate input with zod, and never expose the connection string to the client.Rules, databases & blogs to use
- PostgreSQL rule: SQL conventions
- Database & API rules: database rules by category

