Skip to content

applyParamsToPostgrest

function applyParamsToPostgrest<B>(builder, params): B;

Defined in: filters/postgrest.ts:503

Add PostgrestParams (from buildParams, buildFilterNode or a keyset’s where) to a postgrest-js / supabase-js query with its public methods: a column param becomes .filter(column, operator, value), or=(…) becomes .or(…), and an and=(…)/not.or=(…) param is wrapped as a one-element .or("and(…)"). Returns the same builder for chaining. Works with any object that has filter and or, so this module never imports @supabase/postgrest-js.

Type Parameter
B extends PostgrestFilterBuilder
Parameter Type
builder B
params PostgrestParams

B

import { applyParamsToPostgrest } from "@xtandard/lib/filters/postgrest";
// in an app: applyParamsToPostgrest(supabase.from("tasks").select(), params)
const calls: unknown[] = [];
const builder = {
filter: (...args: unknown[]) => calls.push(["filter", ...args]),
or: (filters: string) => calls.push(["or", filters]),
};
applyParamsToPostgrest(builder, [["amount", "not.in.(1,2)"], ["not.or", "(a.eq.1,b.eq.2)"]]) === builder; // → true
calls; // → [["filter", "amount", "not.in", "(1,2)"], ["or", "not.or(a.eq.1,b.eq.2)"]]