Skip to content

Commit

Permalink
Refactore ViewQueries
Browse files Browse the repository at this point in the history
Refactor to use an array of list instead of a list of list.

Refactor queries parameter to `IList` instead of an `IEnumerable`

Refactor Tests to use `Length` as they are arrays now

Refactor README.md example to be correct.
  • Loading branch information
panoukos41 committed Mar 17, 2021
1 parent c7787e5 commit 68f5736
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ var results = await _rebels.GetViewQueryAsync<string[], RebelView>("jedi", "by_n
var lukeRows = results[0];
var yodaRows = results[1];
// OR
var details = await _rebels.GetDetailedViewQueryAsync<int, BattleView>("battle", "by_name", queries);
var details = await _rebels.GetDetailedViewQueryAsync<string[], RebelView>("jedi", "by_name", queries);
var lukeDetails = details[0];
var yodaDetails = details[1];
```
Expand Down
12 changes: 6 additions & 6 deletions src/CouchDB.Driver/CouchDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,19 +537,19 @@ public Task<CouchViewList<TKey, TValue, TSource>> GetDetailedViewAsync<TKey, TVa
}

/// <inheritdoc/>
public async Task<List<List<CouchView<TKey, TValue, TSource>>>> GetViewQueryAsync<TKey, TValue>(string design, string view,
IEnumerable<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default)
public async Task<List<CouchView<TKey, TValue, TSource>>[]> GetViewQueryAsync<TKey, TValue>(string design, string view,
IList<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default)
{
List<CouchViewList<TKey, TValue, TSource>> result =
CouchViewList<TKey, TValue, TSource>[] result =
await GetDetailedViewQueryAsync<TKey, TValue>(design, view, queries, cancellationToken)
.ConfigureAwait(false);

return result.Select(x => x.Rows).ToList();
return result.Select(x => x.Rows).ToArray();
}

/// <inheritdoc/>
public async Task<List<CouchViewList<TKey, TValue, TSource>>> GetDetailedViewQueryAsync<TKey, TValue>(string design, string view,
IEnumerable<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default)
public async Task<CouchViewList<TKey, TValue, TSource>[]> GetDetailedViewQueryAsync<TKey, TValue>(string design, string view,
IList<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default)
{
Check.NotNull(design, nameof(design));
Check.NotNull(view, nameof(view));
Expand Down
2 changes: 1 addition & 1 deletion src/CouchDB.Driver/DTOs/CouchViewQueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class CouchViewQueryResult<TKey, TValue, TDoc>
/// The results in the same order as the queries.
/// </summary>
[JsonProperty("results")]
public List<CouchViewList<TKey, TValue, TDoc>> Results { get; set; }
public CouchViewList<TKey, TValue, TDoc>[] Results { get; set; }
}
}
#nullable restore
10 changes: 5 additions & 5 deletions src/CouchDB.Driver/ICouchDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ Task<CouchViewList<TKey, TValue, TSource>> GetDetailedViewAsync<TKey, TValue>(st
/// <param name="view">The view to use.</param>
/// <param name="queries">Multiple query options for the request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a list with a list of <see cref="CouchView{TKey, TValue, TSource}"/> for each query.</returns>
Task<List<List<CouchView<TKey, TValue, TSource>>>> GetViewQueryAsync<TKey, TValue>(string design, string view,
IEnumerable<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default);
/// <returns>A task that represents the asynchronous operation. The task result contains an array with a list of <see cref="CouchView{TKey, TValue, TSource}"/> for each query.</returns>
Task<List<CouchView<TKey, TValue, TSource>>[]> GetViewQueryAsync<TKey, TValue>(string design, string view,
IList<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default);

/// <summary>
/// Executes the specified view function from the specified design document using
Expand All @@ -140,8 +140,8 @@ Task<List<List<CouchView<TKey, TValue, TSource>>>> GetViewQueryAsync<TKey, TValu
/// <param name="queries">Multiple query options for the request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation. The task result contains a list with a <see cref="CouchViewList{TKey, TSource, TView}"/> for each query.</returns>
Task<List<CouchViewList<TKey, TValue, TSource>>> GetDetailedViewQueryAsync<TKey, TValue>(string design, string view,
IEnumerable<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default);
Task<CouchViewList<TKey, TValue, TSource>[]> GetDetailedViewQueryAsync<TKey, TValue>(string design, string view,
IList<CouchViewOptions<TKey>> queries, CancellationToken cancellationToken = default);

/// <summary>
/// Since CouchDB v3, it is deprecated (a no-op).
Expand Down
4 changes: 2 additions & 2 deletions tests/CouchDB.Driver.UnitTests/Database_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public async Task GetViewQueryAsync()
var results = await _rebels.GetViewQueryAsync<string[], RebelView>("jedi", "by_name", queries);

// Assert
Assert.Equal(2, results.Count);
Assert.Equal(2, results.Length);

Assert.All(results, result =>
{
Expand Down Expand Up @@ -428,7 +428,7 @@ public async Task GetDetailedViewQueryAsync()
var results = await _rebels.GetDetailedViewQueryAsync<string[], RebelView>("jedi", "by_name", queries);

// Assert
Assert.Equal(2, results.Count);
Assert.Equal(2, results.Length);

Assert.All(results, result =>
{
Expand Down

0 comments on commit 68f5736

Please sign in to comment.