def _apply_params(self, cursor: Cursor): cursor.skip(self._offset) if self._limit is not None: cursor.limit(self._limit) if len(self._order_by) > 0: order_by = [ (column, DESCENDING if desc else ASCENDING) for column, desc in self._order_by ] cursor.sort(order_by) return cursor
def get_pagination_from_cursor(cursor: Cursor, start: int, limit: int): total = cursor.count() results = cursor.skip(start).limit(limit) has_next = total > (start + limit) pagination = { "start": start, "limit": limit, "total": total, "hasNext": has_next, "results": list(results) } return pagination
def paginate(cursor: Cursor, *, offset: int, limit: int) -> Cursor: if offset: cursor = cursor.skip(offset) if limit is not None: cursor = cursor.limit(limit) return cursor