-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDatabaseCommand.SelectQuery.cs
More file actions
50 lines (46 loc) · 2.92 KB
/
Copy pathDatabaseCommand.SelectQuery.cs
File metadata and controls
50 lines (46 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace CoreEx.Database;
public abstract partial class DatabaseCommand
{
/// <summary>
/// Selects none or more items from the first result set.
/// </summary>
/// <typeparam name="T">The item <see cref="Type"/>.</typeparam>
/// <param name="func">The <see cref="DatabaseRecord"/> mapping function.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The resulting set.</returns>
public Task<IEnumerable<T>> SelectQueryAsync<T>(Func<DatabaseRecord, OperationType, T> func, CancellationToken cancellationToken = default)
=> SelectQueryAsync(new DatabaseMapper<T>(func.ThrowIfNull()), cancellationToken);
/// <summary>
/// Selects none or more items from the first result set using a <paramref name="mapper"/>.
/// </summary>
/// <typeparam name="T">The item <see cref="Type"/>.</typeparam>
/// <param name="mapper">The <see cref="IDatabaseMapper{T}"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The item sequence.</returns>
public async Task<IEnumerable<T>> SelectQueryAsync<T>(IDatabaseMapper<T> mapper, CancellationToken cancellationToken = default)
{
var coll = new List<T>();
await SelectQueryAsync(coll, mapper, cancellationToken).ConfigureAwait(false);
return coll;
}
/// <summary>
/// Selects none or more items from the first result set and adds to the <paramref name="collection"/>.
/// </summary>
/// <typeparam name="T">The item <see cref="Type"/>.</typeparam>
/// <typeparam name="TColl">The collection <see cref="Type"/>.</typeparam>
/// <param name="collection">The collection.</param>
/// <param name="func">The <see cref="DatabaseRecord"/> mapping function.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public Task SelectQueryAsync<T, TColl>(TColl collection, Func<DatabaseRecord, OperationType, T> func, CancellationToken cancellationToken = default) where TColl : ICollection<T>
=> SelectQueryAsync(collection, new DatabaseMapper<T>(func), cancellationToken);
/// <summary>
/// Selects none or more items from the first result set and adds to the <paramref name="collection"/>.
/// </summary>
/// <typeparam name="T">The item <see cref="Type"/>.</typeparam>
/// <typeparam name="TColl">The collection <see cref="Type"/>.</typeparam>
/// <param name="collection">The collection.</param>
/// <param name="mapper">The <see cref="IDatabaseMapper{T}"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
public Task SelectQueryAsync<T, TColl>(TColl collection, IDatabaseMapper<T> mapper, CancellationToken cancellationToken = default) where TColl : ICollection<T>
=> SelectInternalAsync(collection, mapper, false, false, int.MaxValue, nameof(SelectQueryAsync), cancellationToken);
}