Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PostgrestClient<Database, SchemaName, Schema>

PostgREST client.

Type Parameters

  • Database = any

    Types for the schema from the type generator

  • SchemaName extends string & keyof Database = "public" extends keyof Database ? "public" : string & keyof Database

    Postgres schema to switch to. Must be a string literal, the same one passed to the constructor. If the schema is not "public", this must be supplied manually.

  • Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? Database[SchemaName] : any

Hierarchy

  • PostgrestClient

Index

Constructors

  • new PostgrestClient<Database, SchemaName, Schema>(url: string, options?: { fetch?: ((input: RequestInfo, init?: RequestInit) => Promise<Response>); headers?: Record<string, string>; schema?: SchemaName }): PostgrestClient<Database, SchemaName, Schema>
  • Creates a PostgREST client.

    Type Parameters

    • Database = any

    • SchemaName extends string = "public" extends keyof Database ? "public" : string & keyof Database

    • Schema extends GenericSchema = Database[SchemaName] extends GenericSchema ? any[any] : any

    Parameters

    • url: string

      URL of the PostgREST endpoint

    • options: { fetch?: ((input: RequestInfo, init?: RequestInit) => Promise<Response>); headers?: Record<string, string>; schema?: SchemaName } = {}

      Named parameters

      • Optional fetch?: ((input: RequestInfo, init?: RequestInit) => Promise<Response>)
          • (input: RequestInfo, init?: RequestInit): Promise<Response>
          • Custom fetch

            Parameters

            • input: RequestInfo
            • Optional init: RequestInit

            Returns Promise<Response>

      • Optional headers?: Record<string, string>

        Custom headers

      • Optional schema?: SchemaName

        Postgres schema to switch to

    Returns PostgrestClient<Database, SchemaName, Schema>

Properties

fetch?: ((input: RequestInfo, init?: RequestInit) => Promise<Response>)

Type declaration

    • (input: RequestInfo, init?: RequestInit): Promise<Response>
    • Parameters

      • input: RequestInfo
      • Optional init: RequestInit

      Returns Promise<Response>

headers: Record<string, string>
schemaName?: SchemaName
url: string

Methods

  • from<TableName, Table>(relation: TableName): PostgrestQueryBuilder<Schema, Table, TableName, Table extends { Relationships: R } ? R : unknown>
  • from<ViewName, View>(relation: ViewName): PostgrestQueryBuilder<Schema, View, ViewName, View extends { Relationships: R } ? R : unknown>
  • Perform a query on a table or a view.

    Type Parameters

    • TableName extends string

    • Table extends GenericTable

    Parameters

    • relation: TableName

      The table or view name to query

    Returns PostgrestQueryBuilder<Schema, Table, TableName, Table extends { Relationships: R } ? R : unknown>

  • Perform a query on a table or a view.

    Type Parameters

    • ViewName extends string

    • View extends GenericView

    Parameters

    • relation: ViewName

      The table or view name to query

    Returns PostgrestQueryBuilder<Schema, View, ViewName, View extends { Relationships: R } ? R : unknown>

  • rpc<FnName, Fn>(fn: FnName, args?: Fn["Args"], options?: { count?: "exact" | "planned" | "estimated"; get?: boolean; head?: boolean }): PostgrestFilterBuilder<Schema, Fn["Returns"] extends any[] ? any[any][number] extends Record<string, unknown> ? any[any][number] : never : never, Fn["Returns"], FnName, null>
  • Perform a function call.

    Type Parameters

    • FnName extends string

    • Fn extends GenericFunction

    Parameters

    • fn: FnName

      The function name to call

    • args: Fn["Args"] = {}

      The arguments to pass to the function call

    • options: { count?: "exact" | "planned" | "estimated"; get?: boolean; head?: boolean } = {}

      Named parameters

      • Optional count?: "exact" | "planned" | "estimated"

        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.

      • Optional get?: boolean

        When set to true, the function will be called with read-only access mode.

      • Optional head?: boolean

        When set to true, data will not be returned. Useful if you only need the count.

    Returns PostgrestFilterBuilder<Schema, Fn["Returns"] extends any[] ? any[any][number] extends Record<string, unknown> ? any[any][number] : never : never, Fn["Returns"], FnName, null>

  • schema<DynamicSchema>(schema: DynamicSchema): PostgrestClient<Database, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? any[any] : any>
  • Select a schema to query or perform an function (rpc) call.

    The schema needs to be on the list of exposed schemas inside Supabase.

    Type Parameters

    • DynamicSchema extends string

    Parameters

    • schema: DynamicSchema

      The schema to query

    Returns PostgrestClient<Database, DynamicSchema, Database[DynamicSchema] extends GenericSchema ? any[any] : any>

Generated using TypeDoc