PostgrestBuilder
import { PostgrestBuilder } from "https://esm.sh/@supabase/supabase-js@2.103.0/dist/index.d.mts";§Type Parameters
§Implements
§Constructors
Creates a builder configured for a specific PostgREST request.
import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
const builder = new PostgrestQueryBuilder(
new URL('https://xyzcompany.supabase.co/rest/v1/users'),
{ headers: new Headers({ apikey: 'public-anon-key' }) }
)
Creating a Postgrest query builder
import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
const builder = new PostgrestQueryBuilder(
new URL('https://xyzcompany.supabase.co/rest/v1/users'),
{ headers: new Headers({ apikey: 'public-anon-key' }) }
)
§Properties
§Methods
Override the type of the returned data field in the response.
// Merge with existing types (default behavior)
const query = supabase
.from('users')
.select()
.overrideTypes<{ custom_field: string }>()
// Replace existing types completely
const replaceQuery = supabase
.from('users')
.select()
.overrideTypes<{ id: number; name: string }, { merge: false }>()
A PostgrestBuilder instance with the new type
Complete Override type of successful response
const { data } = await supabase
.from('countries')
.select()
.overrideTypes<Array<MyType>, { merge: false }>()
Complete Override type of object response
const { data } = await supabase
.from('countries')
.select()
.maybeSingle()
.overrideTypes<MyType, { merge: false }>()
Partial Override type of successful response
const { data } = await supabase
.from('countries')
.select()
.overrideTypes<Array<{ status: "A" | "B" }>>()
Partial Override type of object response
const { data } = await supabase
.from('countries')
.select()
.maybeSingle()
.overrideTypes<{ status: "A" | "B" }>()
Example 5
// Merge with existing types (default behavior)
const query = supabase
.from('users')
.select()
.overrideTypes<{ custom_field: string }>()
// Replace existing types completely
const replaceQuery = supabase
.from('users')
.select()
.overrideTypes<{ id: number; name: string }, { merge: false }>()
- Whether to enable retries for this request
// Disable retries for a specific query
const { data, error } = await supabase
.from('users')
.select()
.retry(false)
Override the type of the returned data.
Use overrideTypes<yourType, { merge: false }>() method at the end of your call chain instead
Strip null values from the response data. Properties with null values
will be omitted from the returned JSON objects.
Requires PostgREST 11.2.0+.
https://docs.postgrest.org/en/stable/references/api/resource_representation.html#stripped-nulls
With select()
const { data, error } = await supabase
.from('characters')
.select()
.stripNulls()
If there's an error with the query, throwOnError will reject the promise by throwing the error instead of returning it as part of a successful response.