WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Function buildCursorPagination

    • Builds Prisma cursor-based pagination parameters for high-performance pagination.

      This utility creates cursor-based pagination parameters for Prisma queries, which is more efficient than offset-based pagination for large datasets. It takes one extra item to determine if there's a next page and uses the cursor to position the query correctly.

      Note: This is prepared for future implementation of cursor-based pagination as an alternative to the current offset/page-based approaches.

      Parameters

      • Optionalcursor: string

        Cursor value (typically an ID) to start pagination from

      • Optionallimit: number = 20

        Number of items to retrieve

      • OptionalsortField: string = 'createdAt'

        Field to sort by for consistent ordering

      Returns any

      Prisma query parameters for cursor-based pagination

      // First page (no cursor)
      const params = buildCursorPagination();
      // Returns: { take: 21, orderBy: { createdAt: 'desc' } }
      // Subsequent page with cursor
      const params = buildCursorPagination('clx123abc', 10, 'updatedAt');
      // Returns: {
      // take: 11,
      // orderBy: { updatedAt: 'desc' },
      // cursor: { id: 'clx123abc' },
      // skip: 1
      // }