Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

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 }?: {
head?: boolean;
get?: boolean;
count?: "exact" | "planned" | "estimated";
}
,
): PostgrestFilterBuilder<ClientOptions, Schema, FilterBuilder["Row"], FilterBuilder["Result"], FilterBuilder["RelationName"], FilterBuilder["Relationships"], "RPC">;
schema<DynamicSchema extends string & keyof Omit<Database, "__InternalSupabase">>(schema: DynamicSchema): PostgrestClient<Database, ClientOptions, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any>;
}

§Type Parameters

§
Database = any
[src]
§
ClientOptions extends ClientServerOptions = (Database extends {
__InternalSupabase: infer I extends ClientServerOptions;
}
? I : {}
)
[src]
§
SchemaName extends string & keyof Omit<Database, "__InternalSupabase"> = ("public" extends keyof Omit<Database, "__InternalSupabase"> ? "public" : string & keyof Omit<Database, "__InternalSupabase">)
[src]
§
Schema extends GenericSchema = (Omit<Database, "__InternalSupabase">[SchemaName] extends GenericSchema ? Omit<Database, "__InternalSupabase">[SchemaName] : any)
[src]

§Constructors

§
new PostgrestClient(url: string, { headers, schema, fetch }?: {
headers?: HeadersInit;
schema?: SchemaName;
fetch?: Fetch;
}
)
[src]

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

§
fetch: Fetch
[src]
§
headers: Headers
[src]
§
schemaName: SchemaName
[src]
§
url: string
[src]

§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 }?: {
head?: boolean;
get?: boolean;
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, FilterBuilder["Row"], FilterBuilder["Result"], FilterBuilder["RelationName"], FilterBuilder["Relationships"], "RPC">
[src]

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, data will 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

"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