Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Add StreamAsync alternatives to support IAsyncEnumerable

Open dwfrancis opened this issue 3 years ago • 7 comments

Add StreamAsync alternatives to connecton.QueryAsync and gridReader.ReadAsync to support IAsyncEnumerable in a non-breaking way.

Unlike QueryAsync, stream will default to unbuffered.

dwfrancis avatar Aug 04 '21 03:08 dwfrancis

Intentionally omitted cancellation tokens to keep the signatures similar.

Since these are new I can include them.

dwfrancis avatar Aug 04 '21 03:08 dwfrancis

Re-authored commits (forgot to reset git config from a work account)

dwfrancis avatar Nov 26 '21 15:11 dwfrancis

Completes the "new IAsyncEnumerable<T> API" task in V2 API refactors #1293

dwfrancis avatar Jan 03 '22 15:01 dwfrancis

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: @.***>

mgravell avatar Jan 03 '22 19:01 mgravell

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. 👍

fdcastel avatar Jun 19 '22 05:06 fdcastel

I'm also waiting for that :D

Sonic198 avatar Sep 09 '22 10:09 Sonic198

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.

pcooper avatar Sep 09 '22 13:09 pcooper

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.

Conbag93 avatar Oct 10 '22 11:10 Conbag93

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.

SoftStoneDevelop avatar Feb 08 '23 17:02 SoftStoneDevelop

Any updates on that? 👀

ronimizy avatar May 14 '23 10:05 ronimizy

Any updates on that? 👀

No, Dapper seems to be abandoned.

SoftStoneDevelop avatar May 14 '23 16:05 SoftStoneDevelop

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

mgravell avatar Jun 09 '23 15:06 mgravell