Skip to content
Drivers/PostgREST

PostgREST

driverpostgrest5/8 capabilities

Import the driver directly so every other driver tree-shakes away.

postgrest.ts
import { POSTGREST_DRIVER, QubeeStore, QueryBuilder, Paginator } from '@qubeejs/core';
const store = new QubeeStore();
const qb = new QueryBuilder(store, POSTGREST_DRIVER.createRequestStrategy('query'));
const paginator = new Paginator(
store,
POSTGREST_DRIVER.createResponseStrategy(),
POSTGREST_DRIVER.createResponseOptions({}),
);
qb.setResource('articles')
.addFilter('status', 'published')
.addSort('createdAt', SortEnum.DESC)
.setLimit(25)
.generateUri();

Produces:

/articles?status=eq.published&order=createdAt.desc&limit=25
Capability Supported
Filters ✅
Operators ✅
Sort ✅
Select ✅
Fields —
Includes —
Search —
Embedded ✅

The totals travel in the response headers, so pass them as the second argument:

const response = await fetch(`https://example.com/api${uri}`);
const page = paginator.paginate(await response.json(), response.headers);
page.data; // rows
page.total; // total rows the backend reported
page.lastPage; // final page number