createMany
Category
Tags
Export size
min 7.23 kB · gzip 2.95 kB
See also
Creates all given items with a single create([...]) call.
If the service does not allow multi creating (its multi option, or an explicit multi option), the items are created with one call per item instead, at most concurrency at a time - so it works regardless of the service's multi configuration. A single item is always created with a single call.
ts
import { createMany } from 'feathers-utils/utils';Example
ts
import { createMany } from 'feathers-utils/utils'
// one `create([...])` call, or one `create({...})` call per item
const todos = await createMany(app, 'todos', [
{ title: 'Buy milk', userId: 1 },
{ title: 'Buy eggs', userId: 1 },
])Options
Type declaration
Show Type Declarations
ts
export type CreateManyOptions<P extends Params = Params> = {
/**
* Whether the service allows creating multiple items in a single call.
*
* Defaults to the `multi` option of the service. If multi creating is not
* allowed, the items are created with one call per item.
*/
multi?: Multi
/**
* How many `create` calls run at the same time when the items are created
* with one call per item, so a long list does not exhaust the database pool.
*
* @default 10
*/
concurrency?: number
/**
* The params of every `create` call - e.g. to create the items in the
* caller's transaction.
*
* @example { transaction: context.params.transaction }
*/
params?: P
}
/**
* Creates all given items with a single `create([...])` call.
*
* If the service does not allow multi creating (its `multi` option, or an
* explicit `multi` option), the items are created with one call per item
* instead, at most `concurrency` at a time - so it works regardless of the
* service's `multi` configuration.
* A single item is always created with a single call.
*
* @example
* ```ts
*
*
* // one `create([...])` call, or one `create({...})` call per item
* const todos = await createMany(app, 'todos', [
* { title: 'Buy milk', userId: 1 },
* { title: 'Buy eggs', userId: 1 },
* ])
* ```
*
* @see https://utils.feathersjs.com/utils/create-many.html
*/
export declare function createMany<
Services,
Path extends KeyOf<Services>,
Service extends Services[Path] = Services[Path],
Item = InferCreateResultSingle<Service>,
>(
app: Application<Services>,
servicePath: Path,
data: InferCreateDataSingle<Service>[],
options?: CreateManyOptions<InferCreateParams<Service>>,
): Promise<Item[]>| Argument | Type | Description |
|---|---|---|
| app | Application<Services> | |
| servicePath | Path | |
| data | InferCreateDataSingle<Service>[] | |
| options | CreateManyOptions<InferCreateParams<Service>> |
