getQueryBefore()function
getQueryBefore(query: Query<T>, item: T, caller: AnyCaller = getQueryBefore): Query<T>
| Param | Type | |
|---|---|---|
query | Query<T> | The query to page through. It must have an $order. required |
item | T | The item to page from (normally the first item already loaded). required |
caller | AnyCaller | Any calling function or constructor, usually referring to something that can call in the current scope that can appear in a stack trace. Defaults to getQueryBefore |
| Return | |
|---|---|
Query<T> | A new query with the range added. |
| Throws | |
|---|---|
RequiredError | If the query has no $order, or item has no value for the first $order key. |
Get a query for the items that sort at or before a specified item.
- For cursor-based paging towards the start of a result set.
- Adds an inclusive range on the first
$orderkey only (key<=for an ascending order,key>=for a descending order), so items with the same value asitemare included. Drop the items you already have by ID. - Keeps the existing order and limit. To get the nearest items first, reverse the order before you set a limit.
- Page on a first key with many distinct values (e.g. a timestamp). Many items with the same value make each page read them all again.
Examples
getQueryBefore({ $order: "!when" }, { id: "a", when: 5 }) // { $order: "!when", "when>=": 5 }