Prisma client extension function to find many results in batches.
NOTE: Requires Prisma 4.7.0 or later with
previewFeatures = ["clientExtensions"]
in schema.prisma. https://www.prisma.io/docs/concepts/components/prisma-client/client-extensions
client.MODEL_NAME.findInBatches({ maxPages: Infinity, take: 1000, ...query }, callbackFn);
// Find all users in batches with @gmail.com email
client.user.findInBatches({ where: { email: { endsWith: '@gmail.com' } } }, async (results, page) => {
// Do something with results
});
// Find first 2000 users names and email addresses in batches of 100 skipping the first 500 users
client.user.findInBatches(
{ maxPages: 20, skip: 500, take: 100, select: { name: true, email: true } },
async (results, page) => {
// Do something with results
},
);