?
Query
TypeA lazy, chainable, batchable read. Nothing runs until you await it.
The lazy result of a read. Building a Query with filter, sortBy, take, skip, and reverse composes SQL but runs nothing. It executes only when you await it or pass it to db.batch, which lets several reads share one round trip. Because it is thenable, it also exposes .then and .catch for per-query error handling.
Query.ts
interface Query<T> { filter(predicate, bindings?): Query<T> sortBy(accessor): Query<T> take(n): Query<T> skip(n): Query<T> reverse(): Query<T> then(onResolved): Promise<T> }
Fields
filter
(predicate, bindings?)
Narrow the result with a SQL WHERE clause.
sortBy / reverse
(accessor)
Order the result; reverse flips it to descending.
take / skip
(n)
Limit and offset, for top-n reads and pagination.
then / catch
ThenableAwaiting the Query runs it; catch handles a single read's error.
Compose, then await
const top = Posts.sortBy((p) => p.score).reverse().take(10); const rows = await top; // runs here