Prisma IDB FaviconPrisma IDB
CRUD Operations

createMany

Insert multiple records efficiently

Insert multiple records in a single operation.

const result = await client.user.createMany({
  data: [
    { name: "Alice", email: "alice@example.com" },
    { name: "Bob", email: "bob@example.com" },
    { name: "Charlie", email: "charlie@example.com" },
  ],
});

console.log(`Created ${result.count} users`);

Return Type

createMany returns a count object:

interface CreateManyResult {
  count: number; // Number of records created
}

If you need the actual created records, use createManyAndReturn instead.

With Options

const result = await client.user.createMany(
  {
    data: [
      { name: "Alice", email: "alice@example.com" },
      { name: "Bob", email: "bob@example.com" },
    ],
    skipDuplicates: true, // Skip records that would violate unique constraints
  },
  {
    tx: transaction, // Use existing transaction
    silent: false, // Emit events for each (default: false)
    addToOutbox: true, // Queue for sync (default: true if sync is enabled)
  }
);

Batch Processing

Process large datasets in batches:

const items = [
  /* 10000 items */
];
const batchSize = 100;

for (let i = 0; i < items.length; i += batchSize) {
  const batch = items.slice(i, i + batchSize);

  await client.item.createMany({
    data: batch,
  });
}

Events

Multiple create events are emitted (unless silent: true):

let createCount = 0;

client.user.subscribe(["create"], () => {
  createCount++;
});

await client.user.createMany({
  data: [
    { name: "Alice", email: "alice@example.com" },
    { name: "Bob", email: "bob@example.com" },
  ],
});

console.log(`${createCount} create events emitted`); // 2

See Also

On this page