UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

42 lines (41 loc) 1.98 kB
import { DocIdOrDocIdObj, DocumentData } from '../../internal-common/src/public-types/document.public-types'; import { QueryBuilder } from './query/query-builder.factory'; /** * Result of the `visitQueryResults` function. * @category Database */ export interface VisitQueryResultsStats { /** Count of documents visited. */ count: number; /** Time in millis spent in the function. */ time: number; } /** * Reads all objects from the query in a safe way (with pagination) and calls callback() on every object. * The iteration is interrupted if error is thrown. * @category Database */ export declare function visitQueryResults<T extends DocumentData>(query: QueryBuilder<T>, callback: (t: T) => Promise<unknown>, pageSize?: number): Promise<VisitQueryResultsStats>; /** * Paginates through the query and returns the docIds of all matching documents in a form * that can be passed back to `collection.doc(id)` to retrieve the same documents. Does * NOT read `ref.data` — only the index identifiers — so it is safe to call when document * data is being mutated concurrently, and uses O(N) of small ids rather than O(N) of * full document payloads. * * Use this instead of `visitQueryResults` when the per-row processing may mutate the same * collection in a way that affects which documents match the query. Live pagination breaks * in that case: a write that takes a row out of the result set evicts refs in the same * page (DataManager reacts globally to mutations), and subsequent `ref.data` reads throw * "No data found". The recommended pattern is: * * const ids = await loadQueryResultDocIds(query); * for (const id of ids) { * const doc = await collection.doc(id).snapshot(); * if (!doc) continue; * // ...mutate doc... * } * * @category Database */ export declare function loadQueryResultDocIds<T extends DocumentData>(query: QueryBuilder<T>, pageSize?: number): Promise<Array<DocIdOrDocIdObj>>;