better-supabase
A typed data layer for Supabase: generated repositories that return Results and run under RLS, auth helpers, framework adapters and a CLI.

Docs · Quickstart · Blocks · Examples · Changelog · GitHub
better-supabase sits on the supabase-js client you already use. You keep your database, your RLS policies, Supabase Auth and Storage. The CLI reads your schema and generates a typed repository for every table, so a query is a typed object instead of a string. It is an independent, MIT-licensed project built on the official Supabase packages, not a Supabase product, and the raw client stays one property away as db.$client.
The same query, typed
With supabase-js, the columns and relations are a string, a filter on a related table needs !inner and a dotted path, and the error is a Postgres or PostgREST code:
const { data, error } = await supabase
.from("customers")
.select("id, name, organization(name), notes!inner(kind)")
.eq("status", "active")
.eq("notes.kind", "call")
.order("name")
.limit(20);
if (error) throw error;
With better-supabase, the same read is an object the compiler checks, the row type follows from select and include, and the call returns a Result instead of throwing:
const result = await db.customers.list({
select: ["id", "name"],
where: { status: "active", notes: { some: { kind: "call" } } },
include: { organization: { select: ["name"] } },
orderBy: { name: "asc" },
limit: 20,
});
if (!result.ok) {
// result.error.kind is "unauthorized", "timeout", "network" and so on
return Response.json(result.error, { status: result.error.status });
}
result.data; // { id: string; name: string; organization: { name: string } }[]
It is still one PostgREST request, and it runs as the signed-in user, so your RLS policies decide what it can read. Call .orThrow() when you would rather throw. The supabase-js migration guide maps every supabase-js call to its repository equivalent.
What you get
| Feature | What it does |
|---|
| Stronger generated types | gen writes the same database.types.ts as supabase gen types, and adds relationship cardinality, unique keys, CHECK-constraint unions, typed jsonb and per-table flags. |
| A typed repository | list, get and the writes take where, include, orderBy and pagination, and compile to one PostgREST request, or to SQL on the direct-Postgres path. |
| Results, not exceptions | Every call returns a Result with a plain, serializable DbError, safe to return from server actions and RPC handlers. |
| Queries as the caller | connect() runs per request with the user's client, so every query runs under their RLS policies. Rows keep your casing, snake_case or camelCase. |
| Auth without round trips | A valid access token is verified locally and never reaches the Auth server. Refresh happens once, in the proxy. |
| Caches that follow writes | Writes invalidate the cache tags of the tables they touch, and the generated data hooks refetch. |
| Checks before you ship | doctor reports missing RLS, grants and indexes, config and env drift, and the Supabase advisors. |