sleeplessS
Convex Community5mo ago
2 replies
sleepless

hello, I'm working on a generic util

hello, I'm working on a generic util that takes a query and deletes all documents
this is the general idea
export const deleteAllInQuery = async <T extends GenericTableInfo>(ctx: MutationCtx, q: OrderedQuery<T>, cursor: string | null) => {
  do {
    const result = await q.paginate({
      cursor,
      numItems: 100,
    });
    await Promise.all(
      result.page.map(async (item) => {
        await ctx.db.delete(item._id as Id<TableNamesInDataModel<DataModel>>);
      }),
    );
    cursor = result.continueCursor;
  } while (cursor);
};


From what I understand, to avoid potentially running into limits, each batch should be scheduled separately, but how can I pass a query to an interalMutation?
Was this page helpful?