iterateFind
utils
Source Code | DocumentationUse for await to iterate over the results of a find method.
This function is useful for iterating over large datasets without loading everything into memory at once. It uses pagination to fetch results in chunks, allowing you to process each item as it is retrieved.
ts
import { iterateFind } from 'feathers-utils/utils';Example
ts
import { iterateFind } from 'feathers-utils/utils'
const app = feathers()
// Assuming 'users' service has many records
for await (const user of iterateFind(app, 'users', {
params: { query: { active: true }, // Custom query parameters
} })) {
console.log(user) // Process each user record
}Type declaration
Show Type Declarations
ts
type IterateFindOptions<P extends Params = Params> = {
params?: P
}
/**
* Use `for await` to iterate over the results of a `find` method.
*
* This function is useful for iterating over large datasets without loading everything into memory at once.
* It uses pagination to fetch results in chunks, allowing you to process each item as it is retrieved.
*
* @example
* ```ts
*
*
* const app = feathers()
*
* // Assuming 'users' service has many records
* for await (const user of iterateFind(app, 'users', {
* params: { query: { active: true }, // Custom query parameters
* } })) {
* console.log(user) // Process each user record
* }
* ```
*
* @see https://utils.feathersjs.com/utils/iterate-find.html
*/
export declare function iterateFind<
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?: IterateFindOptions<P>,
): AsyncGenerator<Item, void, unknown>| Argument | Type | Description |
|---|---|---|
| app | Application<Services> | |
| servicePath | Path | |
| options | IterateFindOptions<P> |
