Skip to content

patchMany ​

Category
Tags
Export size
min 7.61 kB · gzip 3.08 kB
See also

Patches all items matching params with a single patch(null, ...) call.

If the service does not allow multi patching (its multi option, or an explicit multi option), the matching items are fetched with find and patched with one call per item instead, at most concurrency at a time - so it works regardless of the service's multi configuration.

The params only select which items are affected: the query is consumed by the find - which only collects the ids - and is not applied again for the per-item calls, except $select.

ts
  import { 
patchMany
} from 'feathers-utils/utils';

Example ​

ts
import { patchMany } from 'feathers-utils/utils'

// one `patch(null, ...)` call, or one `patch(id, ...)` call per item
const todos = await patchMany(app, 'todos', { userId: null }, {
  query: { userId: 1 },
})

Options ​

multiMulti

Whether the service allows patching multiple items in a single call.

Defaults to the multi option of the service. If multi patching is not allowed, the matching items are fetched and patched with one call per item.

concurrencynumberdefault10

How many patch calls run at the same time when the items are patched with one call per item, so a large match does not exhaust the database pool.

Type declaration ​

Show Type Declarations
ts
export type PatchManyOptions = {
  /**
   * Whether the service allows patching multiple items in a single call.
   *
   * Defaults to the `multi` option of the service. If multi patching is not
   * allowed, the matching items are fetched and patched with one call per item.
   */
  multi?: Multi
  /**
   * How many `patch` calls run at the same time when the items are patched with
   * one call per item, so a large match does not exhaust the database pool.
   *
   * @default 10
   */
  concurrency?: number
}
/**
 * Patches all items matching `params` with a single `patch(null, ...)` call.
 *
 * If the service does not allow multi patching (its `multi` option, or an
 * explicit `multi` option), the matching items are fetched with `find` and
 * patched with one call per item instead, at most `concurrency` at a time - so
 * it works regardless of the service's `multi` configuration.
 *
 * The `params` only select which items are affected: the query is consumed by
 * the `find` - which only collects the ids - and is not applied again for the
 * per-item calls, except `$select`.
 *
 * @example
 * ```ts
 *
 *
 * // one `patch(null, ...)` call, or one `patch(id, ...)` call per item
 * const todos = await patchMany(app, 'todos', { userId: null }, {
 *   query: { userId: 1 },
 * })
 * ```
 *
 * @see https://utils.feathersjs.com/utils/patch-many.html
 */
export declare function patchMany<
  Services,
  Path extends KeyOf<Services>,
  Service extends Services[Path] = Services[Path],
  P extends Params = InferFindParams<Service>,
  Item = InferFindResultSingle<Service>,
>(
  app: Application<Services>,
  servicePath: Path,
  data: InferPatchData<Service>,
  params?: P,
  options?: PatchManyOptions,
): Promise<Item[]>
ArgumentTypeDescription
appApplication<Services>
servicePathPath
dataInferPatchData<Service>
paramsP
optionsPatchManyOptions

Released under the MIT License.