Skip to content

Commit 766d8a0

Browse files
committed
Add Type Generation section
1 parent b526a69 commit 766d8a0

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

docs/integrations/supabase.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,73 @@ This is extremely helpful for verifying that your function is running correctly
316316
317317
:::
318318
319+
### Type Generation
320+
321+
Dreamflow can generate fully typed TypeScript definitions based on your database schema. These types ensure your Edge Functions stay in sync with your tables, columns, and relationships, providing safer queries and better autocomplete during development.
322+
323+
For example, without types you might accidentally write:
324+
325+
```tsx
326+
await supabase.from("profiles").insert({ fullName: "Mike" });
327+
// ❌ Bug: "fullName" is not a column in the profiles table
328+
```
329+
330+
This won’t fail until the app is actually running.
331+
332+
With generated types, TypeScript immediately catches the mistake:
333+
334+
```tsx
335+
// ❌ TypeScript error: "fullName" does not exist on type Insert<profiles>
336+
```
337+
338+
Instead of guessing column names or discovering mistakes only at runtime, you get immediate feedback and accurate autocomplete based on your real schema.
339+
340+
#### Generate Types from Database Schema
341+
342+
You can easily generate the `database.types.ts` file by asking the Dreamflow agent.
343+
344+
Use this Agent prompt:
345+
346+
```jsx
347+
Generate a `database.types.ts` file for my connected Supabase project based on the current database schema.
348+
```
349+
350+
:::warning
351+
Types do not update automatically. You must regenerate them whenever your database schema changes.
352+
:::
353+
354+
#### Use Generated Types
355+
356+
Inside any Edge Function, you can import the generated types:
357+
358+
```tsx
359+
import { Database } from "../../database.types.ts";
360+
```
361+
362+
Then you can use them like this:
363+
364+
**Example: Type-safe Table Insert**
365+
366+
```tsx
367+
type ProfileInsert = Database["public"]["Tables"]["profiles"]["Insert"];
368+
369+
await supabase.from("profiles").insert<ProfileInsert>({
370+
id: userId,
371+
display_name: name,
372+
});
373+
```
374+
375+
**Example: Strongly-typed Row**
376+
377+
```tsx
378+
type ProfileRow = Database["public"]["Tables"]["profiles"]["Row"];
379+
380+
const { data } = await supabase.from("profiles").select("*").eq("id", userId);
381+
382+
const profile: ProfileRow = data[0]; // typed and validated
383+
```
384+
385+
319386
### Best Practices
320387
321388
- **Each Function Lives in Its Own Folder**: Every edge function should have its own directory containing an `index.ts` entry file. For example:

0 commit comments

Comments
 (0)