pb.search
API reference for the search endpoint and the from() query builder.
pb.search() runs one or more named queries in one HTTP request. Use from() to build each query with editor hints for valid model fields. Then, call .build() before you pass the query to pb.search().
For a full tutorial, see the Search guide.
pb.search(queries): Execute search queries
Fires POST /search.
const = await .({
: ('packs').('last_activity_at').(10).(),
: ('profiles').('created_at').(5).(),
})
if (!(.)) {
.(.topPacks)}Parameters:
| Param | Type | Description |
|---|---|---|
queries | NamedQueryMap | An object mapping query names to QueryInput objects. |
Returns: A typed named result map. The object uses the names from queries. Each value is a SearchPost[], SearchProfile[], SearchPack[], or ErrorEntry. Use isErrorEntry() before you process the value as data. Search rows keep database names such as images_avatar. They do not use normalized nested resource fields.
from(model): Query builder
Creates a query builder for the selected model. The chain does not send a request. .build() makes the request data, and pb.search() sends it.
const query = ('packs') // start a query on 'packs' .({ : 'uuid' }) // filter
.('last_activity_at') // sort
.(20) // limit
.() // serialize to QueryInputBuilder methods
| Method | Description |
|---|---|
.where(conditions) | Add AND filter conditions. Merges on multiple calls. |
.and(conditions[]) | Explicit AND across multiple condition objects. |
.or(conditions[]) | OR across multiple condition objects. |
.not(conditions) | Exclude records matching conditions. |
.orderBy(field, direction?) | Sort by field. Default direction is 'desc'. |
.take(count) | Limit results. |
.skip(count) | Offset results. |
.page(page, pageSize?) | Calls .take(pageSize).skip((page-1)*pageSize). |
.build() | Returns a QueryInput to pass to pb.search(). |
isErrorEntry(result): Type guard
One named query can fail while other queries in the same request are successful. Use this helper to identify whether a specified result is an error or data:
const { } = await .({
: ('packs').(),
})
if (()) {
.(packs.)} else {
.(packs)}Type reference
import type { , , , ErrorEntry } from '@packbase/sdk-ts'
// ModelName is a union of all queryable models
type _Model =
// SortDirection
type _Sort =