Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Unspeakable Type Workaround #1843

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions src/BenchmarksApps/TodosApi/DataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,6 @@ public static Task<NpgsqlDataReader> QueryAsync(this NpgsqlCommand command, Canc
public static Task<NpgsqlDataReader> QueryAsync(this NpgsqlCommand command, CommandBehavior commandBehavior, CancellationToken cancellationToken = default)
=> command.ExecuteReaderAsync(commandBehavior, cancellationToken);

public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> enumerable, CancellationToken cancellationToken)
=> ToListAsync(enumerable, null, cancellationToken);

public static async Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> enumerable, int? initialCapacity = null, CancellationToken cancellationToken = default)
{
var list = initialCapacity.HasValue ? new List<T>(initialCapacity.Value) : new List<T>();

await foreach (var item in enumerable.WithCancellation(cancellationToken))
{
list.Add(item);
}

return list;
}

public static NpgsqlParameterCollection AddTyped<T>(this NpgsqlParameterCollection parameters, T? value)
{
parameters.Add(new NpgsqlParameter<T>
Expand Down
9 changes: 3 additions & 6 deletions src/BenchmarksApps/TodosApi/TodoApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ public static RouteGroupBuilder MapTodoApi(this IEndpointRouteBuilder routes)

group.AddValidationFilter();

// BUG: Having to call ToListAsync() on query results until JSON support for unspeakable types (https://github.com/dotnet/aspnetcore/issues/47548) is resolved

group.MapGet("/", (NpgsqlDataSource db, CancellationToken ct) =>
db.QueryAsync<Todo>("SELECT * FROM Todos", ct).ToListAsync(ct))
db.QueryAsync<Todo>("SELECT * FROM Todos", ct))
.WithName("GetAllTodos");

group.MapGet("/complete", (NpgsqlDataSource db, CancellationToken ct) =>
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = true", ct).ToListAsync(ct))
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = true", ct))
.WithName("GetCompleteTodos");

group.MapGet("/incomplete", (NpgsqlDataSource db, CancellationToken ct) =>
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = false", ct).ToListAsync(ct))
db.QueryAsync<Todo>("SELECT * FROM Todos WHERE IsComplete = false", ct))
.WithName("GetIncompleteTodos");

group.MapGet("/{id:int}", async Task<Results<Ok<Todo>, NotFound>> (int id, NpgsqlDataSource db, CancellationToken ct) =>
Expand Down Expand Up @@ -104,7 +102,6 @@ await db.ExecuteAsync(
}

[JsonSerializable(typeof(Todo))]
[JsonSerializable(typeof(List<Todo>))]
[JsonSerializable(typeof(IAsyncEnumerable<Todo>))]
internal partial class TodoApiJsonSerializerContext : JsonSerializerContext
{
Expand Down