feat: implement an async iterable request class
This PR implements an async iterable request class.
The new class IterableRequest is implemented as a super class of the normal Request class. It is an AsyncIterable providing an AsyncIterator and can be used with for await.
Usage:
const request = new IterableRequest("select 42, 'hello world'");
connection.execSql(request);
for await (const item of request) {
console.log(item.row);
}
A unit test is included. The API documentation has yet to be written.
Implements #1550
Codecov Report
Attention: Patch coverage is 83.69565% with 15 lines in your changes missing coverage. Please review.
Project coverage is 78.39%. Comparing base (
65ab37d) to head (9691e11). Report is 16 commits behind head on master.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/iterable-request.ts | 83.69% | 9 Missing and 6 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #1644 +/- ##
==========================================
- Coverage 79.01% 78.39% -0.63%
==========================================
Files 93 91 -2
Lines 4876 4947 +71
Branches 937 948 +11
==========================================
+ Hits 3853 3878 +25
- Misses 720 768 +48
+ Partials 303 301 -2
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
First of all, this is super exciting - thank you for working on this! ❤️
I haven't taken a super deep look into the implementation yet, but my idea for this was always to change the API for request execution to something like this:
// Create a new request, but without callback.
const request = new Request('select a, b, c from foobar');
// `using` so any resources are free'd to make the connection reusable in case some error happens in the user's code
using response = await connection.execSql(request);
// `.values` for a rows as arrays
// `.objects` for rows as objects
for await (const [a, b, c] of response.values()) {
...
}
Obviously, making such a profound change to the API is not simple, and there's going to be a lot of concerns around backwards compatibility and things like that.