Casing
snake_case or camelCase models, mapped at the edge of the database.
Set casing in the config. A config without it uses 'snake', which keeps
database names as they are; better-supabase init writes casing: "camel"
unless you pass --casing snake.
export default defineConfig({ gen: { casing: "camel" } });With 'camel', models, filters, includes and returned rows use camelCase.
The mapping happens in the query itself, not in a post-processing pass:
await db.customers.list({ select: ["id", "organizationId"] });
// GET /customers?select=id,organizationId:organization_idPostgREST renames the columns in its response, so rows need no transform and nested includes keep their shape.
Per-table overrides
export default defineConfig({
gen: { casing: "camel", tables: { legacy_events: { casing: "snake" } } },
});Function results
db.$rpc returns rows of a table (returns setof customers) and records
(returns table (customer_id uuid, total numeric)) in the configured casing,
with the same codecs as reads. gen records which functions need it in the
metadata, so other results, such as a scalar, json or jsonb, come back
as Postgres sent them:
const rows = await db
.$rpc("customers_by_status", { p_status: "lead" })
.orThrow();
rows[0].organizationId;returns validates the decoded value, so a schema for the cased row works.
When a result column has a codec, such as an int8 read as a bigint or a
numeric read as a string, $rpc selects the result columns and casts
those to text, as repository reads do. A JSON number would already have
lost an int8 above 2^53 or a numeric's digits before the codec saw it.
{ raw: true } skips the decoding and the cast, and returns database names,
typed as unknown.
A scalar int8 or numeric result, or one inside a json or jsonb
result, has no columns to cast: return it as text from the function when
it can be that large. doctor reports scalar ones as BS223. The blocks'
own functions return every int8 as text, and their clients read it back
as a bigint or a Money.
What stays in database names
- Constraint names (
onConflict: 'customers_organization_id_kvk_key'). - Plugin config columns (
softDelete: { column: 'archived_at' }): these name database columns, and the generated flags hold the app names. - Raw SQL, RPC argument names and the keys inside
jsonresults.
Error details keep the database name in constraint and columns, since
they come from Postgres.
Last updated on