feat(orm): chunk_by_id_desc + Laravel orderedChunkById parity#167
Merged
Conversation
Extend keyset chunking to full Laravel orderedChunkById parity: - chunk_by_id_desc(size, column, alias): descending keyset pagination (ORDER BY col DESC, WHERE col < last_seen), as a Model classmethod and builder-chainable, mirroring Laravel chunkByIdDesc. - chunk_by_id now honours a pre-set builder offset (first page only) and limit with limit-remaining semantics, e.g. limit(250) chunked by 100 yields 100 + 100 + 50; and raises when the alias column is absent from the result set. The chunk()/chunk_by_id() public behaviour is unchanged: the new descending flag defaults to False and offset/limit are only consulted when the caller set them. Rewrites the chunk test suite in unittest assertion style on a dedicated seeded sqlite table, covering ascending/descending ordering, where chaining, offset/limit-remaining, the alias guard, and delete-safety in both directions.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
Author
Code Review Verdict — APPROVE ✅ (posted as comment; GitHub blocks self-approval on this account)Reviewed the full diff (builder.py, model.py, test_model_chunk.py — 176/125, no unrelated files touched). Verified statically and reproduced all claims locally from Correctness — verified
Laravel fidelityMirrors TestsReal sqlite-backed unittest-style on seeded Reproduced independently (from
|
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.
Summary
Follow-up to #166. Brings the async ORM's keyset chunking to full parity with Laravel's
orderedChunkByIdand adds the descending variant, without changing the already-mergedchunk()/chunk_by_id()public behaviour.What changed
QueryBuilder.chunk_by_id_desc(count, column=None, alias=None)+Model.chunk_by_id_desc(...)— descending keyset pagination (ORDER BY col DESC,WHERE col < last_seen), mirroring LaravelchunkByIdDesc. Works as a classmethod and chained after builder methods.orderedChunkByIdparity inchunk_by_id:.limit(250)chunked by100yields100 + 100 + 50.RuntimeErrorwhen thealiascolumn is absent from the result set (the gap flagged in the feat(orm): Laravel-style chunk() and chunk_by_id() on the async ORM #166 review), read from raw attributes so the model caster doesn't mask it.descendingflag (defaultFalse) shared withchunk_by_id_desc.No public behaviour change
chunk()andchunk_by_id()behave exactly as merged in #166: the newdescendingflag defaults toFalse, and offset/limit are only consulted when the caller set them.Testing
Chunk test suite rewritten in unittest assertion style (repo precedent: task #357), on a dedicated seeded
chunk_itemssqlite table (ids 1..10) plus the seededcountriestable for a non-idprimary key. Covers: ascending/descending ordering and batch sizes,where(...)chaining, offset/limit-remaining, the alias-missing guard, a dedicated alias test, and keyset delete-safety in both directions.uv run pytest --ignore=tests/masoniteorm/postgres --cov→ 1799 passed, 7 skipped, coverage 78.68% (>=fail_under68).ruff check+ruff format --checkclean.Separate from #166 — this PR should get its own review pass.