PostgrestClient
import { PostgrestClient } from "https://esm.sh/@supabase/postgrest-js@2.89.0/dist/index.d.mts";PostgREST client.
class PostgrestClient<Database = any, ClientOptions extends ClientServerOptions = (Database extends { }
__InternalSupabase: infer I extends ClientServerOptions;
} ? I : {}), SchemaName extends string & keyof Omit<Database, "__InternalSupabase"> = ("public" extends keyof Omit<Database, "__InternalSupabase"> ? "public" : string & keyof Omit<Database, "__InternalSupabase">), Schema extends GenericSchema = (Omit<Database, "__InternalSupabase">[SchemaName] extends GenericSchema ? Omit<Database, "__InternalSupabase">[SchemaName] : any)> {constructor(url: string, { headers, schema, fetch }?: {
headers?: HeadersInit;
schema?: SchemaName;
fetch?: Fetch;
});fetch?: Fetch;
headers: Headers;
schemaName?: SchemaName;
url: string;
from<TableName$1 extends string & keyof Schema["Tables"], Table extends Schema["Tables"][TableName$1]>(relation: TableName$1): PostgrestQueryBuilder<ClientOptions, Schema, Table, TableName$1>;
from<ViewName extends string & keyof Schema["Views"], View extends Schema["Views"][ViewName]>(relation: ViewName): PostgrestQueryBuilder<ClientOptions, Schema, View, ViewName>;
rpc<FnName extends string & keyof Schema["Functions"], Args extends Schema["Functions"][FnName]["Args"] = never, FilterBuilder extends GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args> = GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args>>(
fn: FnName,
args?: Args,
{ head, get, count }?: {
): PostgrestFilterBuilder<ClientOptions, Schema, FilterBuilder["Row"], FilterBuilder["Result"], FilterBuilder["RelationName"], FilterBuilder["Relationships"], "RPC">;head?: boolean;
get?: boolean;
count?: "exact" | "planned" | "estimated";
},schema<DynamicSchema extends string & keyof Omit<Database, "__InternalSupabase">>(schema: DynamicSchema): PostgrestClient<Database, ClientOptions, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any>;
§Type Parameters
§
ClientOptions extends ClientServerOptions = (Database extends {
[src]__InternalSupabase: infer I extends ClientServerOptions;
} ? I : {})§Constructors
§
new PostgrestClient(url: string, { headers, schema, fetch }?: {
[src]headers?: HeadersInit;
schema?: SchemaName;
fetch?: Fetch;
})Creates a PostgREST client.
@param url
- URL of the PostgREST endpoint
@param options
- Named parameters
@param options.headers
- Custom headers
@param options.schema
- Postgres schema to switch to
@param options.fetch
- Custom fetch
@example
import PostgrestClient from '@supabase/postgrest-js'
const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
headers: { apikey: 'public-anon-key' },
schema: 'public',
})
§Properties
§Methods
§
from<TableName$1 extends string & keyof Schema["Tables"], Table extends Schema["Tables"][TableName$1]>(relation: TableName$1): PostgrestQueryBuilder<ClientOptions, Schema, Table, TableName$1>
[src]from<ViewName extends string & keyof Schema["Views"], View extends Schema["Views"][ViewName]>(relation: ViewName): PostgrestQueryBuilder<ClientOptions, Schema, View, ViewName>
[src]§
rpc<FnName extends string & keyof Schema["Functions"], Args extends Schema["Functions"][FnName]["Args"] = never, FilterBuilder extends GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args> = GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args>>(fn: FnName, args?: Args, { head, get, count }?: {
[src]head?: boolean;
get?: boolean;
count?: "exact" | "planned" | "estimated";
}): PostgrestFilterBuilder<ClientOptions, Schema, FilterBuilder["Row"], FilterBuilder["Result"], FilterBuilder["RelationName"], FilterBuilder["Relationships"], "RPC">Perform a function call.
@param fn
- The function name to call
@param args
- The arguments to pass to the function call
@param options
- Named parameters
@param options.head
- When set to
true,datawill not be returned. Useful if you only need the count.
@param options.get
- When set to
true, the function will be called with read-only access mode.
@param options.count
- Count algorithm to use to count rows returned by the function. Only applicable for set-returning functions.
"exact": Exact but slow count algorithm. Performs a COUNT(*) under the
hood.
"planned": Approximated but fast count algorithm. Uses the Postgres
statistics under the hood.
"estimated": Uses exact count for low numbers and planned count for high
numbers.
@example
// For cross-schema functions where type inference fails, use overrideTypes:
const { data } = await supabase
.schema('schema_b')
.rpc('function_a', {})
.overrideTypes<{ id: string; user_id: string }[]>()
§
schema<DynamicSchema extends string & keyof Omit<Database, "__InternalSupabase">>(schema: DynamicSchema): PostgrestClient<Database, ClientOptions, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any>
[src]Select a schema to query or perform an function (rpc) call.
The schema needs to be on the list of exposed schemas inside Supabase.
@param schema
- The schema to query