Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Iterable interface for IOperation #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 9, 2024
Merged

Iterable interface for IOperation #252

merged 9 commits into from
May 9, 2024

Conversation

kravets-levko
Copy link
Contributor

@kravets-levko kravets-levko commented Apr 19, 2024

Add an iterable interface for IOperation. Iterators provide a convenient way to process results using for await .. of loop.

Two new methods are offered:

  • IOperation.iterateChunks() - allows to process results like the one would previously do using hasMoreRows + fetchChunk in a loop;
  • IOperation.iterateRows() - allows to iterate over individual rows.

Both methods take the same options as IOperation.fetchChunk. In addition, setting autoClose: true will close the operation when iterator is finished. By default this option is false (do not close operation after iterating).

Due to its nature, IOperation can only supply chunks of records. It means that iterateChunks is somewhat more efficient than iterateRows, because the latter internally also takes chunks and uses nested loop to walk over the rows. But iterating over rows seems to be quite a common use case for the library, therefore iterateRows was also added for convenience.

Important. Since query results can be only retrieved sequentialy from beginning to the end, attempt to use multiple iterators on the same operation may result in unpredictable behavior. Stick with a straightforward use case, when a single for await .. of loop is used to walk through all results from beginning to end. It is allowed to use a break statement within the loop, but after that don't attempt to use iterators for that operation again.

Signed-off-by: Levko Kravets <[email protected]>
Signed-off-by: Levko Kravets <[email protected]>
Signed-off-by: Levko Kravets <[email protected]>
Signed-off-by: Levko Kravets <[email protected]>
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.06%. Comparing base (c239fca) to head (5e8744e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #252      +/-   ##
==========================================
+ Coverage   92.91%   93.06%   +0.14%     
==========================================
  Files          64       65       +1     
  Lines        1553     1586      +33     
  Branches      275      280       +5     
==========================================
+ Hits         1443     1476      +33     
  Misses         46       46              
  Partials       64       64              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kravets-levko kravets-levko merged commit fb817b5 into main May 9, 2024
8 checks passed
@kravets-levko kravets-levko deleted the iterable-operation branch May 9, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants