Dapper
Dapper copied to clipboard
Add StreamAsync alternatives to support IAsyncEnumerable
Add StreamAsync
alternatives to connecton.QueryAsync
and gridReader.ReadAsync
to support IAsyncEnumerable
in a non-breaking way.
Unlike QueryAsync
, stream will default to unbuffered.
Intentionally omitted cancellation tokens to keep the signatures similar.
Since these are new I can include them.
Re-authored commits (forgot to reset git config from a work account)
Completes the "new IAsyncEnumerable<T> API" task in V2 API refactors #1293
Will review when I'm back at in work-mode.
On Mon, 3 Jan 2022, 15:33 David W. Francis, @.***> wrote:
Completes the "new IAsyncEnumerable API" task #1293 https://github.com/DapperLib/Dapper/issues/1293
— Reply to this email directly, view it on GitHub https://github.com/DapperLib/Dapper/pull/1692#issuecomment-1004172504, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEHMHRAQOK5VG6UV36NKTUUG6U7ANCNFSM5BQFLJOQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
Will review when I'm back at in work-mode.
@mgravell... Are you back from your sabbatical? 😅
@dwfrancis Thanks for the excellent work! I'm using the code in some non-production capacity (going into production next month) and so far it is going smoothly. 👍
I'm also waiting for that :D
I was able to work around lack of support with the current stable version by using ExecuteReaderAsync
to get a data reader, then get a row parser from that.
var reader = await connection.ExecuteReaderAsync(sql, param);
var rowParser = reader.GetRowParser<MyType>();
while (await reader.ReadAsync())
{
var value = rowParser(reader);
// Do other sync/async stuff with value.
yield return value;
}
This also worked with dynamic
typed row parser funcs.
Just wanted to also add my thanks to @dwfrancis for this PR. I hope that it gets the offical 'nod' of approval because this has allowed me to experiment with some of the new-ish .net features wiith very minimal code changes.
Combining this with System.Text.Json's newly introduced support for asynchronous Json serialization allows my API to return each row to the client as soon as they are retrieved from the database. Additionally, if the client also knows the "count" ahead-of-time then I can leverage this to track the progress of a long-running query.
It looks like a different implementation of what I did(https://github.com/DapperLib/Dapper/pull/1882) as part of the solution https://github.com/DapperLib/Dapper/issues/1239 (because in the comments to the issue it was https://github.com/DapperLib/Dapper/issues/1239#issuecomment-1035448069).
The fundamental difference is that I rewrote SqlMapper.Async and SqlMapper.GridReader.Async from pseudo-async to IAsyncEnumerable. And of course added "buffered" parameter. Because my opinion is that there should be either a synchronous method or an asynchronous one. A pseudo-asynchronous wrapper over a synchronous one has no right to exist.
My point is that it might be worth choosing one of these two pull requests or considering them together.
Any updates on that? 👀
Any updates on that? 👀
No, Dapper seems to be abandoned.
Dapper is absolutely not abandoned; see #1909 for status; this feature now essentially provided via #1912 - so: I appreciate the input, but I think we should re-address needs when #1912 is in