Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

QueryAsync missing buffered parameter

Open vitidev opened this issue 7 years ago • 8 comments

I can

db.Query<Person>(sql, parameters, buffered: false)

But I can't

db.QueryAsync<Person>(sql, parameters, buffered: false)

At the same time, the multimap overload of QueryAsync has parameter "buffered"

Task<IEnumerable<TReturn>> QueryAsync<TReturn>(this IDbConnection cnn, string sql, Type[] types, Func<object[], TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true,

vitidev avatar Apr 13 '19 11:04 vitidev

Well that's odd. Is there an overload that takes the struct? Maybe that has it?

But: when async iterators lands in c# vNext, we'll need to revisit the non-buffered query-async anyway, as it is only pseudo-async at the moment (by necessity).

On Sat, 13 Apr 2019, 12:31 vitidev, [email protected] wrote:

I can

db.Query<Person>(sql, parameters, buffered: false)

But I can't

db.QueryAsync<Person>(sql, parameters, buffered: false)

At the same time, the multimap overload of QueryAsync has parameter "buffered"

Task<IEnumerable<TReturn>> QueryAsync<TReturn>(this IDbConnection cnn, string sql, Type[] types, Func<object[], TReturn> map, object param = null, IDbTransaction transaction = null, bool buffered = true,

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/StackExchange/Dapper/issues/1239, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsOREEPN9TeUGJnFGuFIAmG79vRKlks5vgcATgaJpZM4ct_z0 .

mgravell avatar Apr 13 '19 12:04 mgravell

@mgravell Yes. I found QueryAsync<T>(this IDbConnection cnn, CommandDefinition command)

But it was expected that synchronous and asynchronous versions will have "mirror" signatures. Sometimes you have to convert Query into QueryAsyncand it's very nice when it's enough to add Async(+await) and that is all

as it is only pseudo-async at the moment

That all the same it is good, it is possible not to hold a current thread waiting for the response from a database

when async iterators lands in c# vNext

Async enumerators are good, but a little incomprehensible why you can not do without them like

 var reader = await db.ExecuteAsyncReaderAsync(); // 
 while (await reader.ReadAsync())
 {
       var value = reader.GetChar(0);
 }

 var reader = await db.QueryReaderAsync<Person>();
 while (await reader.MoveNext())
 {
      var value = reader.Current;
 }

Or is it already there and I do not read the documentation well?

vitidev avatar Apr 13 '19 13:04 vitidev

You absolutely can do that as long as you're happy for the consuming code to do that work but a execute-reader and getting the per-T materializer separately. The point here is that until C# vNext, neither "foreach" nor "yield return" support this scenario, so you can't just return a sequence. That's what vNext gives us: "await foreach".

On Sat, 13 Apr 2019, 14:25 vitidev, [email protected] wrote:

@mgravell https://github.com/mgravell Yes. I found QueryAsync<T>(this IDbConnection cnn, CommandDefinition command)

But it was expected that synchronous and asynchronous versions will have "mirror" signatures. Sometimes you have to convert Query into QueryAsyncand it's very nice when it's enough to add Async(+await) and that is all

as it is only pseudo-async at the moment

That all the same it is good, it is possible not to hold a current thread waiting for the response from a database

when async iterators lands in c# vNext

Async enumerators are good, but a little incomprehensible why you can not do without them like

var reader = await db.ExecuteAsyncReaderAsync(); // while (await reader.ReadAsync()) { var value = reader.GetChar(0); }

var reader = await db.QueryReaderAsync<Person>(); while (await reader.MoveNext()) { var value = reader.Current; }

Or is it already there and I do not read the documentation well?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/StackExchange/Dapper/issues/1239#issuecomment-482808965, or mute the thread https://github.com/notifications/unsubscribe-auth/AABDsFsWCmXZZlEpxtFsoLU-whZ7wIXRks5vgdq7gaJpZM4ct_z0 .

mgravell avatar Apr 13 '19 14:04 mgravell

@mgravell await foreach is out there now. Any plans to support this now?

ravimp avatar Feb 10 '22 20:02 ravimp

Plans, yes. What I need is time. Working through some redis and protobuf bits, then I should be able to take a look at Dapper

mgravell avatar Feb 10 '22 20:02 mgravell

@mgravell, Dapper has been such a help, I'd like to return the favor. I think I can contribute if someone points me in the right direction. Meanwhile, I got this from an SO post. Do you think it is a reliable workaround until we get an API for it?

using var reader = await connection.ExecuteReaderAsync(query, parameters);
var rowParser = reader.GetRowParser<T>();

while (await reader.ReadAsync()) {
    yield return rowParser(reader);
}

ravimp avatar Feb 10 '22 20:02 ravimp

add some ConfigureAwait(false) and you're probably pretty close; personally I'm also a bit of a stickler for exhausting the reader, because I've seen TDS faults go unreported if this isn't done, so:

while (await reader.ReadAsync()) {
    yield return rowParser(reader);
}
while (await reader.NextResultAsync()) {}

but: up to you

mgravell avatar Feb 10 '22 20:02 mgravell

Did this ever get implemented in dapper directly? I'm at a point where this would be really useful.

Thanks, Sean.

SeanFarrow avatar Mar 24 '22 19:03 SeanFarrow

any news regarding this?

PedroFerreira4470 avatar Dec 29 '22 14:12 PedroFerreira4470

this feature now essentially provided via #1912

mgravell avatar Jun 09 '23 15:06 mgravell