chunkFind
utils
Source Code | DocumentationSee also: utils/iterateFind
Use for await to iterate over chunks (pages) of results from a find method.
This function is useful for processing large datasets in batches without loading everything into memory at once. It uses pagination to fetch results in chunks, yielding each page's data array.
ts
import { } from 'feathers-utils/utils';Example
ts
import { chunkFind } from 'feathers-utils/utils'
const app = feathers()
// Assuming 'users' service has many records
for await (const users of chunkFind(app, 'users', {
params: { query: { active: true }, // Custom query parameters
} })) {
console.log(users) // Process each chunk of user records
}Type declaration
Show Type Declarations
ts
type PaginateOption = {
default?: number
max?: number
}
type ChunkFindOptions<P extends Params = Params> = {
params?: P & {
paginate?: PaginateOption
}
}
/**
* Use `for await` to iterate over chunks (pages) of results from a `find` method.
*
* This function is useful for processing large datasets in batches without loading everything into memory at once.
* It uses pagination to fetch results in chunks, yielding each page's data array.
*
* @example
* ```ts
*
*
* const app = feathers()
*
* // Assuming 'users' service has many records
* for await (const users of chunkFind(app, 'users', {
* params: { query: { active: true }, // Custom query parameters
* } })) {
* console.log(users) // Process each chunk of user records
* }
* ```
*
* @see https://utils.feathersjs.com/utils/chunk-find.html
*/
export declare function chunkFind<
Services,
Path extends KeyOf<Services>,
Service extends Services[Path] = Services[Path],
P extends Params = InferFindParams<Service>,
Item = InferFindResultSingle<Service>,
>(
app: Application<Services>,
servicePath: Path,
options?: ChunkFindOptions<P>,
): AsyncGenerator<Item[], void, unknown>| Argument | Type | Description |
|---|---|---|
| app | Application<Services> | |
| servicePath | Path | |
| options | ChunkFindOptions<P> |
