Skip to content

createMany

Category
Tags
Export size
min 0.78 kB · gzip 0.45 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 - 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 },
])

Type declaration

Show Type Declarations
ts
export type CreateManyOptions = {
  /**
   * 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
}
/**
 * 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 - 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,
): Promise<Item[]>
ArgumentTypeDescription
appApplication<Services>
servicePathPath
dataInferCreateDataSingle<Service>[]
optionsCreateManyOptions

Released under the MIT License.