Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: update docs with new helper types. (#19163)

Thor 雷神 Schaeff3a41744af84d
diff --git a/apps/docs/docs/ref/javascript/typescript-support.mdx b/apps/docs/docs/ref/javascript/typescript-support.mdx
index 0a3163d2572..021617ff9a7 100644
--- a/apps/docs/docs/ref/javascript/typescript-support.mdx
+++ b/apps/docs/docs/ref/javascript/typescript-support.mdx
@@ -158,21 +158,13 @@ const { data } = await supabase.from('countries').select().returns<MyType>()
<RefSubLayout.EducationRow>
<RefSubLayout.Details>
- It's convenient to have shorthands for your most-used types.
+ The generated types provide shorthands for accessing tables and enums.
</RefSubLayout.Details>
<RefSubLayout.Examples>
- ```ts ./database.types.ts
- import { Database } from "./database-generated.types.ts";
- export type { Database } from "./database-generated.types.ts";
-
- export type Tables<T extends keyof Database['public']['Tables']> = Database['public']['Tables'][T]['Row']
- export type Enums<T extends keyof Database['public']['Enums']> = Database['public']['Enums'][T]
- // etc.
- ```
```ts ./index.ts
- import { Database, Tables } from "./database.types.ts";
+ import { Database, Tables, Enums } from "./database.types.ts";
// Before 😕
let movie: Database['public']['Tables']['movies']['Row'] = // ...
@@ -210,23 +202,21 @@ const { data } = await supabase.from('countries').select().returns<MyType>()
</RefSubLayout.Details>
<RefSubLayout.Examples>
- ```ts
- import { PostgrestError } from '@supabase/supabase-js'
-
- export type DbResult<T> = T extends PromiseLike<infer U> ? U : never
- export type DbResultOk<T> = T extends PromiseLike<{ data: infer U }> ? Exclude<U, null> : never
- export type DbResultErr = PostgrestError
- ```
```ts
- const countriesWithCitiesQuery = supabase.from("countries").select(
- `
- id,
- name,
- cities ( id, name )
- `
- );
- type CountriesWithCities = DbResultOk<typeof countriesWithCitiesQuery>;
+ import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js'
+
+ const countriesWithCitiesQuery = supabase
+ .from("countries")
+ .select(`
+ id,
+ name,
+ cities (
+ id,
+ name
+ )
+ `);
+ type CountriesWithCities = QueryData<typeof countriesWithCitiesQuery>;
const { data, error } = await countriesWithCitiesQuery;
if (error) throw error;
diff --git a/apps/docs/pages/guides/api/joins-and-nesting.mdx b/apps/docs/pages/guides/api/joins-and-nesting.mdx
index 0eeb9f961eb..fb9f91471ee 100644
--- a/apps/docs/pages/guides/api/joins-and-nesting.mdx
+++ b/apps/docs/pages/guides/api/joins-and-nesting.mdx
@@ -113,22 +113,17 @@ create table cities (
We can get the nested `CountriesWithCities` type like this:
```ts
-import { PostgrestError } from '@supabase/supabase-js'
+import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js'
-export type DbResult<T> = T extends PromiseLike<infer U> ? U : never
-export type DbResultOk<T> = T extends PromiseLike<{ data: infer U }> ? Exclude<U, null> : never
-export type DbResultErr = PostgrestError
-```
-
-```ts
-const countriesWithCitiesQuery = supabase.from('countries').select(
- `
+const countriesWithCitiesQuery = supabase.from('countries').select(`
id,
name,
- cities ( id, name )
-`
-)
-type CountriesWithCities = DbResultOk<typeof countriesWithCitiesQuery>
+ cities (
+ id,
+ name
+ )
+`)
+type CountriesWithCities = QueryData<typeof countriesWithCitiesQuery>
const { data, error } = await countriesWithCitiesQuery
if (error) throw error
diff --git a/apps/docs/pages/guides/api/rest/generating-types.mdx b/apps/docs/pages/guides/api/rest/generating-types.mdx
index 2f4aad081f9..ac14bc5ba50 100644
--- a/apps/docs/pages/guides/api/rest/generating-types.mdx
+++ b/apps/docs/pages/guides/api/rest/generating-types.mdx
@@ -129,20 +129,10 @@ const { data } = await supabase.from('countries').select().returns<MyType>()
### Type shorthands
-It's convenient to have shorthands for your most-used types.
-
-```ts ./database.types.ts
-import { Database } from './database-generated.types.ts'
-export type { Database } from './database-generated.types.ts'
-
-export type Tables<T extends keyof Database['public']['Tables']> =
- Database['public']['Tables'][T]['Row']
-export type Enums<T extends keyof Database['public']['Enums']> = Database['public']['Enums'][T]
-// etc.
-```
+The generated types provide shorthands for accessing tables and enums.
```ts ./index.ts
-import { Database, Tables } from "./database.types.ts";
+import { Database, Tables, Enums } from "./database.types.ts";
// Before 😕
let movie: Database['public']['Tables']['movies']['Row'] = // ...
@@ -175,22 +165,17 @@ create table cities (
We can get the nested `CountriesWithCities` type like this:
```ts
-import { PostgrestError } from '@supabase/supabase-js'
+import { QueryResult, QueryData, QueryError } from '@supabase/supabase-js'
-export type DbResult<T> = T extends PromiseLike<infer U> ? U : never
-export type DbResultOk<T> = T extends PromiseLike<{ data: infer U }> ? Exclude<U, null> : never
-export type DbResultErr = PostgrestError
-```
-
-```ts
-const countriesWithCitiesQuery = supabase.from('countries').select(
- `
+const countriesWithCitiesQuery = supabase.from('countries').select(`
id,
name,
- cities ( id, name )
-`
-)
-type CountriesWithCities = DbResultOk<typeof countriesWithCitiesQuery>
+ cities (
+ id,
+ name
+ )
+`)
+type CountriesWithCities = QueryData<typeof countriesWithCitiesQuery>
const { data, error } = await countriesWithCitiesQuery
if (error) throw error