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.
1. Generate the file
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:
Run it again whenever the schema changes. Add --schema <name> for a schema other than public, and --type-name to rename the main type.
2. Use it with the client
The generated type describes each table with Row, Insert and Update. Against a real file, the compiler gave these results:
In Insert, a column with a default or a nullable column is optional. In Update, every column is optional.
3. Row types for your components
Enums<'name'> gives the values of a database enum.
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
Functionswith their arguments. A function that returns a custom row type shows asJsonorunknown. - 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_rolekey.