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

PostgrestQueryBuilder

import { PostgrestQueryBuilder } from "https://esm.sh/@supabase/postgrest-js@2.99.2/dist/index.d.mts";
class PostgrestQueryBuilder<ClientOptions extends ClientServerOptions, Schema extends GenericSchema, Relation$1 extends GenericTable | GenericView, RelationName = unknown, Relationships = (Relation$1 extends {
Relationships: infer R;
}
? R : unknown
)
>
{
constructor(url: URL, { headers, schema, fetch, urlLengthLimit }: {
headers?: HeadersInit;
schema?: string;
fetch?: Fetch;
urlLengthLimit?: number;
}
);
private cloneRequestState;
fetch?: Fetch;
headers: Headers;
schema?: string;
signal?: AbortSignal;
url: URL;
urlLengthLimit: number;
 
delete({ count }?: {
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "DELETE">;
insert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row, options?: {
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">;
insert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row[], options?: {
count?: "exact" | "planned" | "estimated";
defaultToNull?: boolean;
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">;
select<Query extends string = "*", ResultOne = GetResult<Schema, Relation$1["Row"], RelationName, Relationships, Query, ClientOptions>>(columns?: Query, options?: {
head?: boolean;
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], ResultOne[], RelationName, Relationships, "GET">;
update<Row extends (Relation$1 extends {
Update: unknown;
}
? Relation$1["Update"] : never
)
>
(values: Row, { count }?: {
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "PATCH">;
upsert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row, options?: {
onConflict?: string;
ignoreDuplicates?: boolean;
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">;
upsert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row[], options?: {
onConflict?: string;
ignoreDuplicates?: boolean;
count?: "exact" | "planned" | "estimated";
defaultToNull?: boolean;
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">;
}

§Type Parameters

§
ClientOptions extends ClientServerOptions
[src]
§
Schema extends GenericSchema
[src]
§
Relation$1 extends GenericTable | GenericView
[src]
§
RelationName = unknown
[src]
§
Relationships = (Relation$1 extends {
Relationships: infer R;
}
? R : unknown
)
[src]

§Constructors

§
new PostgrestQueryBuilder(url: URL, { headers, schema, fetch, urlLengthLimit }: {
headers?: HeadersInit;
schema?: string;
fetch?: Fetch;
urlLengthLimit?: number;
}
)
[src]

Creates a query builder scoped to a Postgres table or view.

@example
import PostgrestQueryBuilder from '@supabase/postgrest-js'

const query = new PostgrestQueryBuilder(
  new URL('https://xyzcompany.supabase.co/rest/v1/users'),
  { headers: { apikey: 'public-anon-key' } }
)

§Properties

§
cloneRequestState
[src]

Clone URL and headers to prevent shared state between operations.

§
fetch: Fetch
[src]
§
headers: Headers
[src]
§
schema: string
[src]
§
signal: AbortSignal
[src]
§
url: URL
[src]
§
urlLengthLimit: number
[src]

§Methods

§
delete({ count }?: {
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "DELETE">
[src]

Perform a DELETE on the table or view.

By default, deleted rows are not returned. To return it, chain the call with .select() after filters.

@param options
  • Named parameters
@param options.count
  • Count algorithm to use to count deleted rows.

"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.

§
insert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row, options?: {
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">
[src]
insert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row[], options?: {
count?: "exact" | "planned" | "estimated";
defaultToNull?: boolean;
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">
[src]
§
select<Query extends string = "*", ResultOne = GetResult<Schema, Relation$1["Row"], RelationName, Relationships, Query, ClientOptions>>(columns?: Query, options?: {
head?: boolean;
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], ResultOne[], RelationName, Relationships, "GET">
[src]

Perform a SELECT query on the table or view.

@param columns
  • The columns to retrieve, separated by commas. Columns can be renamed when returned with customName:columnName
@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.count
  • Count algorithm to use to count rows in the table or view.

"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

Getting your data

const { data, error } = await supabase
  .from('characters')
  .select()
@example
@example
@example

Selecting specific columns

const { data, error } = await supabase
  .from('characters')
  .select('name')
@example
@example
@example
@example

Query referenced tables

const { data, error } = await supabase
  .from('orchestral_sections')
  .select(`
    name,
    instruments (
      name
    )
  `)
@example
@example
@example
@example

Query referenced tables with spaces in their names

const { data, error } = await supabase
  .from('orchestral sections')
  .select(`
    name,
    "musical instruments" (
      name
    )
  `)
@example
@example
@example
@example

Query referenced tables through a join table

const { data, error } = await supabase
  .from('users')
  .select(`
    name,
    teams (
      name
    )
  `)

@example
@example
@example
@example

Query the same referenced table multiple times

const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    from:sender_id(name),
    to:receiver_id(name)
  `)

// To infer types, use the name of the table (in this case `users`) and
// the name of the foreign key constraint.
const { data, error } = await supabase
  .from('messages')
  .select(`
    content,
    from:users!messages_sender_id_fkey(name),
    to:users!messages_receiver_id_fkey(name)
  `)
@example
@example
@example
@example

Query nested foreign tables through a join table

  const { data, error } = await supabase
    .from('games')
    .select(`
      game_id:id,
      away_team:teams!games_away_team_fkey (
        users (
          id,
          name
        )
      )
    `)

@example
@example
@example
@example

Filtering through referenced tables

const { data, error } = await supabase
  .from('instruments')
  .select('name, orchestral_sections(*)')
  .eq('orchestral_sections.name', 'percussion')
@example
@example
@example
@example

Querying referenced table with count

const { data, error } = await supabase
  .from('orchestral_sections')
  .select(`*, instruments(count)`)
@example
@example
@example
@example

Querying with count option

const { count, error } = await supabase
  .from('characters')
  .select('*', { count: 'exact', head: true })
@example
@example
@example
@example

Querying JSON data

const { data, error } = await supabase
  .from('users')
  .select(`
    id, name,
    address->city
  `)
@example
@example
@example
@example

Querying referenced table with inner join

const { data, error } = await supabase
  .from('instruments')
  .select('name, orchestral_sections!inner(name)')
  .eq('orchestral_sections.name', 'woodwinds')
  .limit(1)
@example
@example
@example
@example

Switching schemas per query

const { data, error } = await supabase
  .schema('myschema')
  .from('mytable')
  .select()
@example
@example
§
update<Row extends (Relation$1 extends {
Update: unknown;
}
? Relation$1["Update"] : never
)
>
(values: Row, { count }?: {
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "PATCH">
[src]

Perform an UPDATE on the table or view.

By default, updated rows are not returned. To return it, chain the call with .select() after filters.

@param values
  • The values to update with
@param options
  • Named parameters
@param options.count
  • Count algorithm to use to count updated rows.

"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

Updating your data

const { error } = await supabase
  .from('instruments')
  .update({ name: 'piano' })
  .eq('id', 1)
@example
@example
@example

Update a record and return it

const { data, error } = await supabase
  .from('instruments')
  .update({ name: 'piano' })
  .eq('id', 1)
  .select()
@example
@example
@example
@example

Updating JSON data

const { data, error } = await supabase
  .from('users')
  .update({
    address: {
      street: 'Melrose Place',
      postcode: 90210
    }
  })
  .eq('address->postcode', 90210)
  .select()
@example
@example
§
upsert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row, options?: {
onConflict?: string;
ignoreDuplicates?: boolean;
count?: "exact" | "planned" | "estimated";
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">
[src]
upsert<Row extends (Relation$1 extends {
Insert: unknown;
}
? Relation$1["Insert"] : never
)
>
(values: Row[], options?: {
onConflict?: string;
ignoreDuplicates?: boolean;
count?: "exact" | "planned" | "estimated";
defaultToNull?: boolean;
}
): PostgrestFilterBuilder<ClientOptions, Schema, Relation$1["Row"], null, RelationName, Relationships, "POST">
[src]