Repository navigation
feat: a Pager that cuts a keyset page and the cursor to the next - #7
Merged
Merged
Conversation
Whether there is a next page is only knowable by fetching one row past it,
and until now every caller did that by hand: bind `size + 1`, truncate,
and call `Cursor::after_row` on the last row kept -- two halves of one rule
in two places that had to agree.
`Pager::new(cursor, size)` holds both. `limit()` is what to fetch, one past
the page; `next_page(rows)` keeps the page and, if the extra row came back,
positions the cursor after the last row kept. The result is a plain
`Page { rows, cursor }`, `cursor` being `None` on the last page. The pager
holds no position, so one serves a whole traversal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Whether there is a next page is only knowable by fetching one row past it, and until now every caller did that by hand: bind
size + 1, truncate, and callCursor::after_rowon the last row kept — two halves of one rule in two places that had to agree.Pager::new(cursor, size)— the ordering comes fromcursor(typicallyCursor::new(order_by)); a position it already carries is replaced. Asizeof 0 is taken as 1.Pager::limit()—size + 1, saturating ati64::MAX. The only place the extra row appears.Pager::next_page(rows)— keepssizerows;cursoris after the last one kept if the extra came back,Noneon the last page.Page { pub rows, pub cursor }— plain data.Backward paging (
prev_page,Cursor::before_row) is deliberately left out; it fits on top without changing any of this.Tests: unit tests for
limit, and live SQLite and PostgreSQL tests paging a table through encoded tokens — every row once, a tie broken by the primary key, and an exactly-full last page with no cursor. README's keyset section now shows the pager.