Drivers/PostgREST
PostgREST
driverpostgrest5/8 capabilities
Import the driver directly so every other driver tree-shakes away.
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({}),);Example query
Section titled “Example query”qb.setResource('articles') .addFilter('status', 'published') .addSort('createdAt', SortEnum.DESC) .setLimit(25) .generateUri();Produces:
/articles?status=eq.published&order=createdAt.desc&limit=25Capabilities
Section titled “Capabilities”| Capability | Supported |
|---|---|
| Filters | ✅ |
| Operators | ✅ |
| Sort | ✅ |
| Select | ✅ |
| Fields | — |
| Includes | — |
| Search | — |
| Embedded | ✅ |
Reading a response
Section titled “Reading a response”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; // rowspage.total; // total rows the backend reportedpage.lastPage; // final page number