feat(orm): Laravel-style chunk() and chunk_by_id() on the async ORM#166
Merged
Conversation
Add async-generator chunking to the QueryBuilder with Model classmethod entry points, both chainable after builder methods. - chunk(size): offset/limit paging, yields a Collection per batch and stops on an empty or short batch (no infinite loop). - chunk_by_id(size, column, alias): keyset pagination ordered by the primary key (or given column), filtering col > last_seen each pass so it stays correct when rows change mid-iteration. - Both guard against a non-positive size. Covered by sqlite-backed tests for batching, ordering, where-chaining, empty tables, delete-safety, and size validation.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
✅ Reviewer verdict: APPROVE (self-approval blocked — posting as comment)Reviewed for correctness, Laravel fidelity, async-generator hygiene, termination, and test quality (task #867). Verified locally at c22a312. Correctness & Laravel fidelity
Async-generator hygiene
Termination
Test quality — genuinely behavioral, not hollow
Scope / gates
Non-blocking suggestions
Verdict: APPROVE. Not merging (reviewer role). |
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
Implements Laravel-equivalent chunking on the async Masonite ORM fork (
fastapi_startkit/src/fastapi_startkit/masoniteorm/). Both methods are async generators and yield the ORMCollectionof hydrated models per batch.What changed
QueryBuilder.chunk(count)— offset/limit paging. Yields aCollectionper batch and stops as soon as a batch comes back empty or shorter thancount, so it never loops forever (mirrors Laravelchunk()).QueryBuilder.chunk_by_id(count, column=None, alias=None)— keyset pagination. Orders by the primary key (or a givencolumn) ascending and filterscolumn > last_seenon each pass, so it stays correct when rows are inserted/deleted mid-iteration (mirrors LaravelchunkById()).aliasreads the last-seen value from a differently named selected column when the ordering column is aliased.ValueError).Model.chunk()/Model.chunk_by_id()classmethod entry points, following the existing explicitcls.query()passthrough pattern — usable directly on the model and chainable after builder methods.Testing
New sqlite-backed test module
tests/masoniteorm/models/test_model_chunk.py(14 tests) covering: batch sizes covering all rows, hydratedCollectionbatches, exact-multiple termination,where(...)chaining, empty tables, keyset ordering, custom column, delete-safety mid-iteration, and size validation.uv run pytest --ignore=tests/masoniteorm/postgres --cov→ 1791 passed, 7 skipped, coverage 78.64% (>=fail_under68).ruff check+ruff format --checkclean.No changes to unrelated framework code.