Skip to content

Commit

Permalink
add missing ReadUnbufferedAsync untyped API (#1958)
Browse files Browse the repository at this point in the history
* - add missing ReadUnbufferedAsync untyped API
- remove an impossible branch

* release notes
  • Loading branch information
mgravell authored Sep 13, 2023
1 parent a2d539c commit 61ff85a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable enable
Dapper.SqlMapper.GridReader.DisposeAsync() -> System.Threading.Tasks.ValueTask
Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable<dynamic!>!
Dapper.SqlMapper.GridReader.ReadUnbufferedAsync<T>() -> System.Collections.Generic.IAsyncEnumerable<T>!
static Dapper.SqlMapper.QueryUnbufferedAsync(this System.Data.Common.DbConnection! cnn, string! sql, object? param = null, System.Data.Common.DbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Collections.Generic.IAsyncEnumerable<dynamic!>!
static Dapper.SqlMapper.QueryUnbufferedAsync<T>(this System.Data.Common.DbConnection! cnn, string! sql, object? param = null, System.Data.Common.DbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Collections.Generic.IAsyncEnumerable<T>!
7 changes: 5 additions & 2 deletions Dapper/SqlMapper.GridReader.Async.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -180,7 +179,6 @@ private Task<IEnumerable<T>> ReadAsyncImpl<T>(Type type, bool buffered)
else
{
var result = ReadDeferred<T>(index, deserializer, type);
if (buffered) result = result.ToList(); // for the "not a DbDataReader" scenario
return Task.FromResult(result);
}
}
Expand Down Expand Up @@ -256,6 +254,11 @@ private async Task<IEnumerable<T>> ReadBufferedAsync<T>(int index, Func<DbDataRe
/// <typeparam name="T">The type to read.</typeparam>
public IAsyncEnumerable<T> ReadUnbufferedAsync<T>() => ReadAsyncUnbufferedImpl<T>(typeof(T));

/// <summary>
/// Read the next grid of results.
/// </summary>
public IAsyncEnumerable<dynamic> ReadUnbufferedAsync() => ReadAsyncUnbufferedImpl<dynamic>(typeof(DapperRow));

private IAsyncEnumerable<T> ReadAsyncUnbufferedImpl<T>(Type type)
{
var deserializer = ValidateAndMarkConsumed(type, out var index);
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Note: to get the latest pre-release build, add ` -Pre` to the end of the command

(note: new PRs will not be merged until they add release note wording here)

- add untyped `GridReader.ReadUnbufferedAsync` API (#1958 via @mgravell)

### 2.1.1

- add NRT annotations (#1928 via @mgravell)
Expand Down
20 changes: 20 additions & 0 deletions tests/Dapper.Tests/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ public async Task TestBasicStringUsageViaGridReaderUnbufferedAsync()
Assert.Equal(new[] { "abc", "def", "ghi" }, arr);
}

[Fact]
public async Task TestBasicStringUsageViaGridReaderUnbufferedDynamicAsync()
{
var results = new List<string>();
await using (var grid = await connection.QueryMultipleAsync("select 'abc' as [Foo] union select 'def'; select @txt as [Foo]", new { txt = "ghi" })
.ConfigureAwait(false))
{
while (!grid.IsConsumed)
{
await foreach (var value in grid.ReadUnbufferedAsync()
.ConfigureAwait(false))
{
results.Add((string)value.Foo);
}
}
}
var arr = results.ToArray();
Assert.Equal(new[] { "abc", "def", "ghi" }, arr);
}

[Fact]
public async Task TestBasicStringUsageViaGridReaderUnbufferedAsync_Cancellation()
{
Expand Down

0 comments on commit 61ff85a

Please sign in to comment.