"Previous" link - equivalent to LIMIT x OFFSET y?

I am creating a page system using CouchDB, showing:

  • 10 elements per page
  • link to previous page (if any)
  • link to next page (if any)

From this article on this topic, I understand that use skipis suboptimal and that instead I should use the property startkeyto indicate the first document, read 11 documents from there, display the first 10 and use the 11 th key to display a link to the next page. What bothers me is the link to the previous page. The article says:

Filling out the link to the previous page is as simple as moving the current launch key to the next page. If theres no previous startkey, we are on the first page.

This works when going to the next page: when I go from page 4 to page 5, I remember that the previous page was 4. But when I go from page 5 to page 4, I have no way to transfer startkeyto page 3. How is it can work?

Is it possible (and recommended) to use endkeytogether with skip=10and limit=1to find the first element on the previous page so that I can create a link to it?

+3
source share
2 answers

11 skip, , Futon ( CouchDB).

, : startkey - skip=1, . descending .

, , CouchDB . , - first, - last. :

"next": /db/_view/myview?descending=true&limit=11&startkey=last&skip=1
"back": /db/_view/myview?descending=false&limit=11&startkey=first&skip=1

Et voilà! , descending - false. ( " " CouchDB B-.)

Bonus

docid (limit=1 descending true false) , -, (, , , ).

+6

21 11 - , - . .

0

Source: https://habr.com/ru/post/1769342/


All Articles