Skip to content

TemplateItemPaginateSelector

Selects Items narrowed to a Template or Union with offset paging, adding Property filters, sorting and joins.

  • BaseSelector.PaginateSelector<TItem>.BaseFilterSelector.BaseSortableSelector.BaseHierarchySelector

TItem

The type of each result.

archived(include): this

Chooses whether archived Items are left out, included, or the only results.

boolean | "exclude" | "include" | "only"

true or 'include' to include archived Items, 'only' for archived Items alone, false or 'exclude' to leave them out.

this

Archived Items are left out until this is called.

BaseSelector.archived


assign(input): this

Applies the criteria of an ItemQuery, such as one received from a client, over the current criteria.

ItemQuery

The query to apply; it is validated before use.

this

when input is not a valid ItemQuery.

BaseSelector.assign


debug(): this

Logs the resolved query when the selection runs.

this

BaseSelector.debug


execute(): Promise<PageSelectorResult<TItem>>

Runs the selection and returns the requested page with its totals.

Promise<PageSelectorResult<TItem>>

PaginateSelector.execute


exists(): Promise<boolean>

Checks whether anything matches the selection, without ordering or reading the results, so the database can stop at the first match.

Promise<boolean>

Whether at least one Item matches.

Cheaper than first() on a large set of matches, which sorts every match to find the first. Unlike first() and execute(), the check is not permission filtered: it is true when an Item matches whatever the active principal can read (as with totalCount of a paginated selection). Run it with sudo for a yes/no question about Items the principal may not read.

BaseSelector.exists


filter(condition): this

Restricts results to Items satisfying a condition on their Properties or Relations.

ItemFilter

A Property condition ($equals, $in, $includes, $range), a Relation condition ($exists, $notExists) or a logical combination ($and, $or, $not).

this

when the condition is malformed, or (error-015-property-not-indexed) when a Property condition is used before the selection is narrowed to a Template or Union.

Match a Property value

const match = await participant.selectItems().filter({ operator: '$equals', key: 'slackUserId', value: input.slackUserId }).first();

BaseFilterSelector.filter


first(): Promise<TItem | undefined>

Runs the selection for a single result.

Promise<TItem | undefined>

The first result, or undefined when nothing matches.

PaginateSelector.first


id(itemOrItems): this

Restricts results to the given Items.

SelectorIdInput

One or more identifiers; an empty list matches nothing.

this

BaseSelector.id


join(…relations): this

Replaces the selection with the Items on the far side of a Relation of the selected Items.

…[string, ...string[]]

The keys of the Relations to follow, in order; each hop replaces the selection with the Items on the far side of that Relation, navigable from either side.

this

when the selection is not narrowed to a single Template or Union, or the Relation key is unknown.


joinChildren(child, options?): this

Turns a selection of parents into a selection of their children of a Template or Union.

The Template or Union of the children.

string

Whether to keep children whose parent did not match.

"inner" | "left"

Join mode. An inner join keeps only Items whose counterpart matched; a left join keeps every Item of the joined Template or Union.

Default Value

'inner'

this

Set the parents’ sort before calling, then use sort(['cascade', ...]) on the result to order children by a parent Property first and their own Properties second.

Children of matching parents, ordered by parent then title

const things = await category
.selectItems()
.sort(['title asc'])
.joinChildren(thing)
.sort(['cascade', { direction: 'ascending', key: 'title', caseInsensitive: true }])
.execute();

BaseHierarchySelector.joinChildren


joinParents(parent, options?): this

Turns a selection of children into a selection of their parents of a Template or Union.

The Template or Union of the parents.

string

Whether to keep parents without a matching child.

"inner" | "left"

Join mode. An inner join keeps only Items whose counterpart matched; a left join keeps every Item of the joined Template or Union.

Default Value

'inner'

this

BaseHierarchySelector.joinParents


key(key): this

Restricts results to Items carrying one of the given keys.

string | string[]

One or more keys; each must be a valid key.

this

BaseSelector.key


limit(value): this

Sets the page size.

number

A positive integer.

this

(error-008-invalid-selector-limit) when value is not a positive integer.

PaginateSelector.limit


parent(parentOrParents): this

Restricts results to direct children of the given parents.

SelectorIdInput

One or more parent identifiers; an empty list matches nothing.

this

BaseSelector.parent


search(idx, query): this

Restricts results to Items matching a search query against a search index.

ReadSearchIndexInstance

The search index to query.

SearchQuery

The term and facets to match.

this

BaseSelector.search


sort(condition): this

Orders results by up to two terms.

ItemSort

One or two terms. A term is a Property sort (key, direction, optional caseInsensitive or ordinal), an intrinsic sort on createdAt or state (intrinsic: true), a shortcut string such as 'title asc' or '$createdAt desc', or 'cascade' to place a joined query’s sort at that position.

this

Items without a value for a term sort last ascending and first descending. Property sorts require the selection to be narrowed to a Template or Union.

when a term is malformed, or (error-015-property-not-indexed) when a Property sort is used before the selection is narrowed to a Template or Union.

Order by a Property

const ordered = content.selectItems().sort([{ direction: 'ascending', key: 'title' }]);

BaseSortableSelector.sort


state(state): this

Restricts results to Items in one of the given states.

string | string[]

One or more state keys; an empty list removes the state criterion.

this

BaseSelector.state