Skip to content

QueryBuilder

Type ParameterDefault type
Tunknown

new QueryBuilder<T>(fetch, table, schema?): QueryBuilder<T>

ParameterType
fetchFluxbaseFetch
tablestring
schema?string

QueryBuilder<T>

avg(column): this

Calculate the average of a numeric column

ParameterTypeDescription
columnstringColumn to average

this

Query builder for chaining

// Average price
const { data } = await client.from('products').avg('price').execute()
// Returns: { avg_price: 129.99 }
// Average by category
const { data } = await client.from('products')
.avg('price')
.groupBy('category')
.execute()

count(column): this

Count rows or a specific column

ParameterTypeDefault valueDescription
columnstring"*"Column to count (default: ’*’ for row count)

this

Query builder for chaining

// Count all rows
const { data } = await client.from('users').count().execute()
// Returns: { count: 150 }
// Count non-null values in a column
const { data } = await client.from('orders').count('completed_at').execute()
// Count with grouping
const { data } = await client.from('products')
.count('*')
.groupBy('category')
.execute()
// Returns: [{ category: 'electronics', count: 45 }, { category: 'books', count: 23 }]

groupBy(columns): this

Group results by one or more columns (for use with aggregations)

ParameterTypeDescription
columnsstring | string[]Column name(s) to group by

this

Query builder for chaining

// Group by single column
const { data } = await client.from('orders')
.count('*')
.groupBy('status')
.execute()
// Group by multiple columns
const { data } = await client.from('sales')
.sum('amount')
.groupBy(['region', 'product_category'])
.execute()

max(column): this

Find the maximum value in a column

ParameterTypeDescription
columnstringColumn to find maximum value

this

Query builder for chaining

// Find highest price
const { data } = await client.from('products').max('price').execute()
// Returns: { max_price: 1999.99 }
// Find most recent order
const { data } = await client.from('orders').max('created_at').execute()

min(column): this

Find the minimum value in a column

ParameterTypeDescription
columnstringColumn to find minimum value

this

Query builder for chaining

// Find lowest price
const { data } = await client.from('products').min('price').execute()
// Returns: { min_price: 9.99 }
// Find earliest date
const { data } = await client.from('orders').min('created_at').execute()

sum(column): this

Calculate the sum of a numeric column

ParameterTypeDescription
columnstringColumn to sum

this

Query builder for chaining

// Sum all prices
const { data } = await client.from('products').sum('price').execute()
// Returns: { sum_price: 15420.50 }
// Sum by category
const { data } = await client.from('orders')
.sum('total')
.groupBy('status')
.execute()
// Returns: [{ status: 'completed', sum_total: 12500 }, { status: 'pending', sum_total: 3200 }]

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.

Promise<PostgrestResponse<null>>

Promise confirming deletion

// Delete all inactive users
await client.from('users')
.eq('active', false)
.deleteMany()
// Delete old logs
await client.from('logs')
.lt('created_at', '2024-01-01')
.deleteMany()

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.

ParameterTypeDescription
rowsPartial<T>[]Array of row objects to insert

Promise<PostgrestResponse<T>>

Promise with the inserted rows

// Insert multiple users at once
const { 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(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.

ParameterTypeDescription
dataPartial<T>Data to update matching rows with

Promise<PostgrestResponse<T>>

Promise with the updated rows

// Apply discount to all electronics
const { data } = await client.from('products')
.eq('category', 'electronics')
.updateMany({ discount: 10, updated_at: new Date() })
// Mark all pending orders as processing
const { 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

ParameterType
filtersstring

this

and('status.eq.active,verified.eq.true')
and('age.gte.18,age.lte.65')

containedBy(column, value): this

Check if column is contained by value (Supabase-compatible) For arrays and JSONB

ParameterType
columnstring
valueunknown

this

containedBy('tags', '["news","update"]')

contains(column, value): this

Contains (for arrays and JSONB)

ParameterType
columnstring
valueunknown

this


crosses(column, geojson): this

Check if geometries cross (PostGIS ST_Crosses)

ParameterTypeDescription
columnstringColumn containing geometry/geography data
geojsonunknownGeoJSON object to test crossing

this

crosses('road', { type: 'LineString', coordinates: [[...]] })

delete(): this

Delete rows matching the filters

this


eq(column, value): this

Equal to

ParameterType
columnstring
valueunknown

this


execute(): Promise<PostgrestResponse<T>>

Execute the query and return results

Promise<PostgrestResponse<T>>


filter(column, operator, value): this

Generic filter method using PostgREST syntax (Supabase-compatible)

ParameterType
columnstring
operatorFilterOperator
valueunknown

this

filter('name', 'in', '("Han","Yoda")')
filter('age', 'gte', '18')

gt(column, value): this

Greater than

ParameterType
columnstring
valueunknown

this


gte(column, value): this

Greater than or equal to

ParameterType
columnstring
valueunknown

this


ilike(column, pattern): this

Pattern matching (case-insensitive)

ParameterType
columnstring
patternstring

this


in(column, values): this

Check if value is in array

ParameterType
columnstring
valuesunknown[]

this


insert(data): this

Insert a single row or multiple rows

ParameterType
dataPartial<T> | Partial<T>[]

this


intersects(column, geojson): this

Check if geometries intersect (PostGIS ST_Intersects)

ParameterTypeDescription
columnstringColumn containing geometry/geography data
geojsonunknownGeoJSON object to test intersection with

this

intersects('location', { type: 'Point', coordinates: [-122.4, 37.8] })

is(column, value): this

Check if value is null or not null

ParameterType
columnstring
valuenull | boolean

this


like(column, pattern): this

Pattern matching (case-sensitive)

ParameterType
columnstring
patternstring

this


limit(count): this

Limit number of rows returned

ParameterType
countnumber

this


lt(column, value): this

Less than

ParameterType
columnstring
valueunknown

this


lte(column, value): this

Less than or equal to

ParameterType
columnstring
valueunknown

this


match(conditions): this

Match multiple columns with exact values (Supabase-compatible) Shorthand for multiple .eq() calls

ParameterType
conditionsRecord<string, unknown>

this

match({ id: 1, status: 'active', role: 'admin' })

maybeSingle(): this

Return a single row or null (adds limit(1)) Does not error if no rows found (Supabase-compatible)

this

// Returns null instead of erroring when no row exists
const { data, error } = await client
.from('users')
.select('*')
.eq('id', 999)
.maybeSingle()
// data will be null if no row found

neq(column, value): this

Not equal to

ParameterType
columnstring
valueunknown

this


not(column, operator, value): this

Negate a filter condition (Supabase-compatible)

ParameterType
columnstring
operatorFilterOperator
valueunknown

this

not('status', 'eq', 'deleted')
not('completed_at', 'is', null)

offset(count): this

Skip rows

ParameterType
countnumber

this


or(filters): this

Apply OR logic to filters (Supabase-compatible)

ParameterType
filtersstring

this

or('status.eq.active,status.eq.pending')
or('id.eq.2,name.eq.Han')

order(column, options?): this

Order results

ParameterType
columnstring
options?object
options.ascending?boolean
options.nullsFirst?boolean

this


overlaps(column, value): this

Check if arrays have common elements (Supabase-compatible)

ParameterType
columnstring
valueunknown

this

overlaps('tags', '["news","sports"]')

range(from, to): this

Range selection (pagination)

ParameterType
fromnumber
tonumber

this


select(columns, options?): this

Select columns to return

ParameterTypeDefault value
columnsstring"*"
options?SelectOptionsundefined

this

select('*')
select('id, name, email')
select('id, name, posts(title, content)')
select('*', { count: 'exact' }) // Get exact count
select('*', { count: 'exact', head: true }) // Get count only (no data)

single(): this

Return a single row (adds limit(1)) Errors if no rows found

this


stContains(column, geojson): this

Check if geometry A contains geometry B (PostGIS ST_Contains)

ParameterTypeDescription
columnstringColumn containing geometry/geography data
geojsonunknownGeoJSON object to test containment

this

contains('region', { type: 'Point', coordinates: [-122.4, 37.8] })

stOverlaps(column, geojson): this

Check if geometries spatially overlap (PostGIS ST_Overlaps)

ParameterTypeDescription
columnstringColumn containing geometry/geography data
geojsonunknownGeoJSON object to test overlap

this

stOverlaps('area', { type: 'Polygon', coordinates: [[...]] })

textSearch(column, query): this

Full-text search

ParameterType
columnstring
querystring

this


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 ParameterDefault type
TResult1PostgrestResponse<T>
TResult2never
ParameterType
onfulfilled?null | (value) => TResult1 | PromiseLike<TResult1>
onrejected?null | (reason) => TResult2 | PromiseLike<TResult2>

PromiseLike<TResult1 | TResult2>

// 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()

PromiseLike.then


throwOnError(): Promise<T>

Execute the query and throw an error if one occurs (Supabase-compatible) Returns the data directly instead of { data, error } wrapper

Promise<T>

If the query fails or returns an error

// 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(column, geojson): this

Check if geometries touch (PostGIS ST_Touches)

ParameterTypeDescription
columnstringColumn containing geometry/geography data
geojsonunknownGeoJSON object to test touching

this

touches('boundary', { type: 'LineString', coordinates: [[...]] })

update(data): this

Update rows matching the filters

ParameterType
dataPartial<T>

this


upsert(data, options?): Promise<PostgrestResponse<T>>

Upsert (insert or update) rows (Supabase-compatible)

ParameterTypeDescription
dataPartial<T> | Partial<T>[]Row(s) to upsert
options?UpsertOptionsUpsert options (onConflict, ignoreDuplicates, defaultToNull)

Promise<PostgrestResponse<T>>


within(column, geojson): this

Check if geometry A is within geometry B (PostGIS ST_Within)

ParameterTypeDescription
columnstringColumn containing geometry/geography data
geojsonunknownGeoJSON object to test containment within

this

within('point', { type: 'Polygon', coordinates: [[...]] })