QueryBuilder
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T | unknown |
Implements
Section titled “Implements”PromiseLike<PostgrestResponse<T>>
Constructors
Section titled “Constructors”new QueryBuilder()
Section titled “new QueryBuilder()”new QueryBuilder<
T>(fetch,table,schema?):QueryBuilder<T>
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fetch | FluxbaseFetch |
table | string |
schema? | string |
Returns
Section titled “Returns”QueryBuilder<T>
Aggregation
Section titled “Aggregation”avg(
column):this
Calculate the average of a numeric column
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column to average |
Returns
Section titled “Returns”this
Query builder for chaining
Example
Section titled “Example”// Average priceconst { data } = await client.from('products').avg('price').execute()// Returns: { avg_price: 129.99 }
// Average by categoryconst { data } = await client.from('products') .avg('price') .groupBy('category') .execute()count()
Section titled “count()”count(
column):this
Count rows or a specific column
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
column | string | "*" | Column to count (default: ’*’ for row count) |
Returns
Section titled “Returns”this
Query builder for chaining
Example
Section titled “Example”// Count all rowsconst { data } = await client.from('users').count().execute()// Returns: { count: 150 }
// Count non-null values in a columnconst { data } = await client.from('orders').count('completed_at').execute()
// Count with groupingconst { data } = await client.from('products') .count('*') .groupBy('category') .execute()// Returns: [{ category: 'electronics', count: 45 }, { category: 'books', count: 23 }]groupBy()
Section titled “groupBy()”groupBy(
columns):this
Group results by one or more columns (for use with aggregations)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
columns | string | string[] | Column name(s) to group by |
Returns
Section titled “Returns”this
Query builder for chaining
Example
Section titled “Example”// Group by single columnconst { data } = await client.from('orders') .count('*') .groupBy('status') .execute()
// Group by multiple columnsconst { data } = await client.from('sales') .sum('amount') .groupBy(['region', 'product_category']) .execute()max(
column):this
Find the maximum value in a column
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column to find maximum value |
Returns
Section titled “Returns”this
Query builder for chaining
Example
Section titled “Example”// Find highest priceconst { data } = await client.from('products').max('price').execute()// Returns: { max_price: 1999.99 }
// Find most recent orderconst { data } = await client.from('orders').max('created_at').execute()min(
column):this
Find the minimum value in a column
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column to find minimum value |
Returns
Section titled “Returns”this
Query builder for chaining
Example
Section titled “Example”// Find lowest priceconst { data } = await client.from('products').min('price').execute()// Returns: { min_price: 9.99 }
// Find earliest dateconst { data } = await client.from('orders').min('created_at').execute()sum(
column):this
Calculate the sum of a numeric column
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column to sum |
Returns
Section titled “Returns”this
Query builder for chaining
Example
Section titled “Example”// Sum all pricesconst { data } = await client.from('products').sum('price').execute()// Returns: { sum_price: 15420.50 }
// Sum by categoryconst { data } = await client.from('orders') .sum('total') .groupBy('status') .execute()// Returns: [{ status: 'completed', sum_total: 12500 }, { status: 'pending', sum_total: 3200 }]Batch Operations
Section titled “Batch Operations”deleteMany()
Section titled “deleteMany()”deleteMany():
Promise<PostgrestResponse<null>>
Delete multiple rows matching the filters (batch delete)
Deletes all rows that match the current query filters. This is a convenience method that explicitly shows intent for batch operations.
Returns
Section titled “Returns”Promise<PostgrestResponse<null>>
Promise confirming deletion
Example
Section titled “Example”// Delete all inactive usersawait client.from('users') .eq('active', false) .deleteMany()
// Delete old logsawait client.from('logs') .lt('created_at', '2024-01-01') .deleteMany()insertMany()
Section titled “insertMany()”insertMany(
rows):Promise<PostgrestResponse<T>>
Insert multiple rows in a single request (batch insert)
This is a convenience method that explicitly shows intent for batch operations.
Internally calls insert() with an array.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
rows | Partial<T>[] | Array of row objects to insert |
Returns
Section titled “Returns”Promise<PostgrestResponse<T>>
Promise with the inserted rows
Example
Section titled “Example”// Insert multiple users at onceconst { data } = await client.from('users').insertMany([ { name: 'Alice', email: 'alice@example.com' }, { name: 'Bob', email: 'bob@example.com' }, { name: 'Charlie', email: 'charlie@example.com' }])updateMany()
Section titled “updateMany()”updateMany(
data):Promise<PostgrestResponse<T>>
Update multiple rows matching the filters (batch update)
Updates all rows that match the current query filters. This is a convenience method that explicitly shows intent for batch operations.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | Partial<T> | Data to update matching rows with |
Returns
Section titled “Returns”Promise<PostgrestResponse<T>>
Promise with the updated rows
Example
Section titled “Example”// Apply discount to all electronicsconst { data } = await client.from('products') .eq('category', 'electronics') .updateMany({ discount: 10, updated_at: new Date() })
// Mark all pending orders as processingconst { data } = await client.from('orders') .eq('status', 'pending') .updateMany({ status: 'processing' })and(
filters):this
Apply AND logic to filters (Supabase-compatible) Groups multiple conditions that must all be true
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
filters | string |
Returns
Section titled “Returns”this
Examples
Section titled “Examples”and('status.eq.active,verified.eq.true')and('age.gte.18,age.lte.65')containedBy()
Section titled “containedBy()”containedBy(
column,value):this
Check if column is contained by value (Supabase-compatible) For arrays and JSONB
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
Example
Section titled “Example”containedBy('tags', '["news","update"]')contains()
Section titled “contains()”contains(
column,value):this
Contains (for arrays and JSONB)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
crosses()
Section titled “crosses()”crosses(
column,geojson):this
Check if geometries cross (PostGIS ST_Crosses)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column containing geometry/geography data |
geojson | unknown | GeoJSON object to test crossing |
Returns
Section titled “Returns”this
Example
Section titled “Example”crosses('road', { type: 'LineString', coordinates: [[...]] })delete()
Section titled “delete()”delete():
this
Delete rows matching the filters
Returns
Section titled “Returns”this
eq(
column,value):this
Equal to
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
execute()
Section titled “execute()”execute():
Promise<PostgrestResponse<T>>
Execute the query and return results
Returns
Section titled “Returns”Promise<PostgrestResponse<T>>
filter()
Section titled “filter()”filter(
column,operator,value):this
Generic filter method using PostgREST syntax (Supabase-compatible)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
operator | FilterOperator |
value | unknown |
Returns
Section titled “Returns”this
Examples
Section titled “Examples”filter('name', 'in', '("Han","Yoda")')filter('age', 'gte', '18')gt(
column,value):this
Greater than
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
gte(
column,value):this
Greater than or equal to
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
ilike()
Section titled “ilike()”ilike(
column,pattern):this
Pattern matching (case-insensitive)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
pattern | string |
Returns
Section titled “Returns”this
in(
column,values):this
Check if value is in array
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
values | unknown[] |
Returns
Section titled “Returns”this
insert()
Section titled “insert()”insert(
data):this
Insert a single row or multiple rows
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | Partial<T> | Partial<T>[] |
Returns
Section titled “Returns”this
intersects()
Section titled “intersects()”intersects(
column,geojson):this
Check if geometries intersect (PostGIS ST_Intersects)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column containing geometry/geography data |
geojson | unknown | GeoJSON object to test intersection with |
Returns
Section titled “Returns”this
Example
Section titled “Example”intersects('location', { type: 'Point', coordinates: [-122.4, 37.8] })is(
column,value):this
Check if value is null or not null
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | null | boolean |
Returns
Section titled “Returns”this
like()
Section titled “like()”like(
column,pattern):this
Pattern matching (case-sensitive)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
pattern | string |
Returns
Section titled “Returns”this
limit()
Section titled “limit()”limit(
count):this
Limit number of rows returned
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
count | number |
Returns
Section titled “Returns”this
lt(
column,value):this
Less than
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
lte(
column,value):this
Less than or equal to
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
match()
Section titled “match()”match(
conditions):this
Match multiple columns with exact values (Supabase-compatible) Shorthand for multiple .eq() calls
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
conditions | Record<string, unknown> |
Returns
Section titled “Returns”this
Example
Section titled “Example”match({ id: 1, status: 'active', role: 'admin' })maybeSingle()
Section titled “maybeSingle()”maybeSingle():
this
Return a single row or null (adds limit(1)) Does not error if no rows found (Supabase-compatible)
Returns
Section titled “Returns”this
Example
Section titled “Example”// Returns null instead of erroring when no row existsconst { data, error } = await client .from('users') .select('*') .eq('id', 999) .maybeSingle()// data will be null if no row foundneq(
column,value):this
Not equal to
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
not(
column,operator,value):this
Negate a filter condition (Supabase-compatible)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
operator | FilterOperator |
value | unknown |
Returns
Section titled “Returns”this
Examples
Section titled “Examples”not('status', 'eq', 'deleted')not('completed_at', 'is', null)offset()
Section titled “offset()”offset(
count):this
Skip rows
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
count | number |
Returns
Section titled “Returns”this
or(
filters):this
Apply OR logic to filters (Supabase-compatible)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
filters | string |
Returns
Section titled “Returns”this
Examples
Section titled “Examples”or('status.eq.active,status.eq.pending')or('id.eq.2,name.eq.Han')order()
Section titled “order()”order(
column,options?):this
Order results
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
options? | object |
options.ascending? | boolean |
options.nullsFirst? | boolean |
Returns
Section titled “Returns”this
overlaps()
Section titled “overlaps()”overlaps(
column,value):this
Check if arrays have common elements (Supabase-compatible)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
value | unknown |
Returns
Section titled “Returns”this
Example
Section titled “Example”overlaps('tags', '["news","sports"]')range()
Section titled “range()”range(
from,to):this
Range selection (pagination)
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
from | number |
to | number |
Returns
Section titled “Returns”this
select()
Section titled “select()”select(
columns,options?):this
Select columns to return
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
columns | string | "*" |
options? | SelectOptions | undefined |
Returns
Section titled “Returns”this
Examples
Section titled “Examples”select('*')select('id, name, email')select('id, name, posts(title, content)')select('*', { count: 'exact' }) // Get exact countselect('*', { count: 'exact', head: true }) // Get count only (no data)single()
Section titled “single()”single():
this
Return a single row (adds limit(1)) Errors if no rows found
Returns
Section titled “Returns”this
stContains()
Section titled “stContains()”stContains(
column,geojson):this
Check if geometry A contains geometry B (PostGIS ST_Contains)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column containing geometry/geography data |
geojson | unknown | GeoJSON object to test containment |
Returns
Section titled “Returns”this
Example
Section titled “Example”contains('region', { type: 'Point', coordinates: [-122.4, 37.8] })stOverlaps()
Section titled “stOverlaps()”stOverlaps(
column,geojson):this
Check if geometries spatially overlap (PostGIS ST_Overlaps)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column containing geometry/geography data |
geojson | unknown | GeoJSON object to test overlap |
Returns
Section titled “Returns”this
Example
Section titled “Example”stOverlaps('area', { type: 'Polygon', coordinates: [[...]] })textSearch()
Section titled “textSearch()”textSearch(
column,query):this
Full-text search
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
column | string |
query | string |
Returns
Section titled “Returns”this
then()
Section titled “then()”then<
TResult1,TResult2>(onfulfilled?,onrejected?):PromiseLike<TResult1|TResult2>
Make QueryBuilder awaitable (implements PromiseLike)
This allows using await client.from('table').select() without calling .execute()
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
TResult1 | PostgrestResponse<T> |
TResult2 | never |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
onfulfilled? | null | (value) => TResult1 | PromiseLike<TResult1> |
onrejected? | null | (reason) => TResult2 | PromiseLike<TResult2> |
Returns
Section titled “Returns”PromiseLike<TResult1 | TResult2>
Example
Section titled “Example”// Without .execute() (new way)const { data } = await client.from('users').select('*')
// With .execute() (old way, still supported)const { data } = await client.from('users').select('*').execute()Implementation of
Section titled “Implementation of”PromiseLike.then
throwOnError()
Section titled “throwOnError()”throwOnError():
Promise<T>
Execute the query and throw an error if one occurs (Supabase-compatible) Returns the data directly instead of { data, error } wrapper
Returns
Section titled “Returns”Promise<T>
Throws
Section titled “Throws”If the query fails or returns an error
Example
Section titled “Example”// Throws error instead of returning { data, error }try { const user = await client .from('users') .select('*') .eq('id', 1) .single() .throwOnError()} catch (error) { console.error('Query failed:', error)}touches()
Section titled “touches()”touches(
column,geojson):this
Check if geometries touch (PostGIS ST_Touches)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column containing geometry/geography data |
geojson | unknown | GeoJSON object to test touching |
Returns
Section titled “Returns”this
Example
Section titled “Example”touches('boundary', { type: 'LineString', coordinates: [[...]] })update()
Section titled “update()”update(
data):this
Update rows matching the filters
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | Partial<T> |
Returns
Section titled “Returns”this
upsert()
Section titled “upsert()”upsert(
data,options?):Promise<PostgrestResponse<T>>
Upsert (insert or update) rows (Supabase-compatible)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | Partial<T> | Partial<T>[] | Row(s) to upsert |
options? | UpsertOptions | Upsert options (onConflict, ignoreDuplicates, defaultToNull) |
Returns
Section titled “Returns”Promise<PostgrestResponse<T>>
within()
Section titled “within()”within(
column,geojson):this
Check if geometry A is within geometry B (PostGIS ST_Within)
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
column | string | Column containing geometry/geography data |
geojson | unknown | GeoJSON object to test containment within |
Returns
Section titled “Returns”this
Example
Section titled “Example”within('point', { type: 'Polygon', coordinates: [[...]] })