Aurabase Logo
aurabasedocs
docs›Guides›Generate TypeScript types

Generate TypeScript types from your database

One command turns your tables into types. Your editor then rejects a wrong column or a wrong value before you run anything.

4 min read·Level beginner·Revised on Oct 12, 2026
This English text was generated automatically from the French original and has not been reviewed yet.
#
Generate

1. Generate the file

terminalbash
npx @aurabase/gen --url https://my-app.aurabase.cloud --key "$AURA_ANON_KEY" --out src/types/database.types.ts

The tool reads the schema of your project and writes the file. Without --url and --key, it looks for AURABASE_URL and AURABASE_ANON_KEY (also NEXT_PUBLIC_AURABASE_URL, VITE_AURABASE_URL and AURABASE_SERVICE_ROLE_KEY) in your environment and in .env, .env.local and .env.development.

On a project with two tables and two functions, it answered:

text
[aurabase-gen] ✓ Types écrits dans /tmp/database.types.ts (2 table(s), 2 fonction(s), 0 enum(s), 0 vue(s)).

Run it again whenever the schema changes. Add --schema <name> for a schema other than public, and --type-name to rename the main type.

#
Use

2. Use it with the client

src/lib/aurabase.tstypescript
import { createClient } from '@aurabase/aurabase-js'
import type { Database } from '../types/database.types'

export const aura = createClient<Database>(process.env.AURA_URL!, process.env.AURA_ANON_KEY!)

The generated type describes each table with Row, Insert and Update. Against a real file, the compiler gave these results:

checked.tstypescript
const { data } = await aura.from('todos').select('id, title, done')
const title: string | undefined = data?.[0]?.title   // ok

const wrong: number | undefined = data?.[0]?.title   // error: string is not assignable to number
await aura.from('todos').insert({ title: 1 })         // error: number is not assignable to string
await aura.from('todos').insert({ title: 'ok' })      // ok: the other columns have defaults

In Insert, a column with a default or a nullable column is optional. In Update, every column is optional.

#
Helpers

3. Row types for your components

Todo.tsxtypescript
import type { Tables, TablesInsert, TablesUpdate, Enums } from '../types/database.types'

type Todo = Tables<'todos'>             // a row, as read
type NewTodo = TablesInsert<'todos'>    // what insert() accepts
type TodoPatch = TablesUpdate<'todos'>  // what update() accepts

Enums<'name'> gives the values of a database enum.

#
Limits

4. What is checked

  • A table that is not in the generated file is not rejected: aura.from('anything') still compiles, and its rows are untyped.
  • Functions appear under Functions with their arguments. A function that returns a custom row type shows as Json or unknown.
  • The file reflects the schema at the time you generated it. A column added later is unknown to the types until you run the tool again.
  • Use the public key to generate the types unless some tables are hidden from it. Never commit a service_role key.
Last updated · Oct 12, 2026