feat: Add async iterable support for paginating query results#564
Open
anatolzak wants to merge 3 commits intotywalch:masterfrom
Open
feat: Add async iterable support for paginating query results#564anatolzak wants to merge 3 commits intotywalch:masterfrom
anatolzak wants to merge 3 commits intotywalch:masterfrom
Conversation
✅ Deploy Preview for electrodb-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
closes #563
Summary
AsyncIterablesupport on.go()for query, scan, and collection operations, enablingfor await...ofiteration over pages of DynamoDB results{ data, cursor }, allowing streaming processing, early termination viabreak, and lower memory usage for large result sets.go()still works as aPromisevia.then()/await; async iteration is opt-in.go()execution is now lazy — the request to DynamoDB is deferred until the result is consumed viaawait,.then(), orfor await...ofHow it works
A new
ElectroQueryResultclass wraps query execution. It implements bothPromiseLike(soawait entity.query.go()works exactly as before) andAsyncIterable(sofor await (const page of entity.query.go())yields individual pages). Internally,executeQuerywas refactored from collecting all pages into a single array to anasync generatorthat yields each page as it arrives from DynamoDB.Example