Types
Clients are typed from a Database type in the format produced by supabase gen types typescript. The module reads it from ~~/shared/types/database.types.ts. Without the file, clients are untyped.
const { data } = await usePostgrest().from('todos').select('id, title')
// ^? { id: number, title: string }[] | null
usePostgrest().from('todo') // ❌ compile error: unknown table
Generating the file
The generator only needs a Postgres connection string. It does not depend on Supabase hosting.
Automatically on nuxt dev
export default defineNuxtConfig({
postgrest: {
generateTypes: true,
},
})
NUXT_POSTGREST_DB_URI=postgres://postgres:postgres@localhost:5432/postgres
Types are regenerated on nuxt dev and nuxt prepare. This requires Docker, because the Supabase CLI runs its introspection in a container. Generation never runs during nuxt build, so CI and production builds use the committed file.
Manually
npx supabase gen types typescript \
--db-url "$NUXT_POSTGREST_DB_URI" \
--schema public > shared/types/database.types.ts
Commit the generated file so builds don't need database access.
Non-default schemas
Automatic generation (generateTypes: true) only covers the public schema. For a Database type that also includes another schema, generate it manually with an explicit --schema list, then target it the same way:
npx supabase gen types typescript \
--db-url "$NUXT_POSTGREST_DB_URI" \
--schema public,internal > shared/types/database.types.ts
usePostgrestAdmin().schema('internal').from('audit_log').select('*')