MCPcopy
hub / github.com/msgbyte/tianji / fetchDataByCursor

Function fetchDataByCursor

src/server/utils/prisma.ts:270–320  ·  view source on GitHub ↗
(
  fetchModel: Model,
  options: {
    // where: Record<string, any>;
    where: ExtractFindManyWhereType<Model>;
    select?: ExtractFindManySelectType<Model>;
    limit: number;
    cursor: CursorType;
    cursorName?: string;
    order?: 'asc' | 'desc';
  }
)

Source from the content-addressed store, hash-verified

268 * );
269 */
270export async function fetchDataByCursor<
271 Model extends {
272 findMany: (args?: any) => Prisma.PrismaPromise<any>;
273 },
274 CursorType,
275>(
276 fetchModel: Model,
277 options: {
278 // where: Record<string, any>;
279 where: ExtractFindManyWhereType<Model>;
280 select?: ExtractFindManySelectType<Model>;
281 limit: number;
282 cursor: CursorType;
283 cursorName?: string;
284 order?: 'asc' | 'desc';
285 }
286) {
287 const {
288 where,
289 limit,
290 cursor,
291 select,
292 cursorName = 'id',
293 order = 'desc',
294 } = options;
295 const items: ExtractFindManyReturnType<Model['findMany']> =
296 await fetchModel.findMany({
297 where,
298 select,
299 take: limit + 1,
300 cursor: cursor
301 ? {
302 [cursorName]: cursor,
303 }
304 : undefined,
305 orderBy: {
306 [cursorName]: order,
307 },
308 });
309
310 let nextCursor: CursorType | undefined = undefined;
311 if (items.length > limit) {
312 const nextItem = items.pop()!;
313 nextCursor = nextItem[cursorName];
314 }
315
316 return {
317 items,
318 nextCursor,
319 };
320}

Callers 6

auditLog.tsFile · 0.85
aiGateway.tsFile · 0.85
survey.tsFile · 0.85
website.tsFile · 0.85
aiRouter.tsFile · 0.85
index.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected