-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathICosmosBulkReader.cs
193 lines (179 loc) · 10.4 KB
/
ICosmosBulkReader.cs
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
namespace Atc.Cosmos
{
/// <summary>
/// Represents a reader that can perform bulk reads on Cosmos resources.
/// </summary>
/// <typeparam name="T">
/// The type of <see cref="ICosmosResource"/>
/// to be read by this reader.
/// </typeparam>
public interface ICosmosBulkReader<T>
where T : class, ICosmosResource
{
/// <summary>
/// Attempts to read the specified <typeparamref name="T"/> resource,
/// and returns <c>null</c> if none was found.
/// </summary>
/// <param name="documentId">Id of the resource.</param>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>A <see cref="Task"/> containing the requested <typeparamref name="T"/> resource, or null.</returns>
Task<T?> FindAsync(
string documentId,
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Reads the specified <typeparamref name="T"/> resource from the configured
/// Cosmos collection.
/// </summary>
/// <remarks>
/// A <see cref="CosmosException"/>
/// with StatusCode <see cref="HttpStatusCode.NotFound"/>
/// will be thrown if resource could not be found.
/// </remarks>
/// <param name="documentId">Id of the resource.</param>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>A <see cref="Task"/> the requested <typeparamref name="T"/> resource.</returns>
public Task<T> ReadAsync(
string documentId,
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Reads all the specified <typeparamref name="T"/> resource from the configured
/// Cosmos collection.
/// </summary>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over all the <typeparamref name="T"/> resources.</returns>
public IAsyncEnumerable<T> ReadAllAsync(
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents from the configured Cosmos container.
/// </summary>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="T"/> resources.</returns>
public IAsyncEnumerable<T> QueryAsync(
QueryDefinition query,
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents from the configured Cosmos container and returns a custom result.
/// </summary>
/// <typeparam name="TResult">The type used for the custom query result.</typeparam>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="TResult"/> resources.</returns>
public IAsyncEnumerable<TResult> QueryAsync<TResult>(
QueryDefinition query,
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents across partitions from the configured Cosmos container.
/// </summary>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="T"/> resources.</returns>
public IAsyncEnumerable<T> CrossPartitionQueryAsync(
QueryDefinition query,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents across partitions from the configured Cosmos container and returns a custom result.
/// </summary>
/// <typeparam name="TResult">The type used for the custom query result.</typeparam>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="TResult"/> resources.</returns>
public IAsyncEnumerable<TResult> CrossPartitionQueryAsync<TResult>(
QueryDefinition query,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents across partitions from the configured Cosmos container using pagination.
/// </summary>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="pageSize">The number of items to return per page.</param>
/// <param name="continuationToken">The continuationToken for getting the next page of a previous query.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="T"/> resources.</returns>
public Task<PagedResult<T>> CrossPartitionPagedQueryAsync(
QueryDefinition query,
int? pageSize,
string? continuationToken = default,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents across partitions from the configured Cosmos container using pagination and a custom result.
/// </summary>
/// <typeparam name="TResult">The type used for the custom query result.</typeparam>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="pageSize">The number of items to return per page.</param>
/// <param name="continuationToken">The continuationToken for getting the next page of a previous query.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>A <typeparamref name="TResult"/> containing the custom query result.</returns>
public Task<PagedResult<TResult>> CrossPartitionPagedQueryAsync<TResult>(
QueryDefinition query,
int? pageSize,
string? continuationToken = default,
CancellationToken cancellationToken = default);
/// <summary>
/// Reads all the specified <typeparamref name="T"/> resource from the configured
/// Cosmos collection.
/// </summary>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over all the <typeparamref name="T"/> resources.</returns>
public IAsyncEnumerable<IEnumerable<T>> BatchReadAllAsync(
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents from the configured Cosmos container.
/// </summary>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="T"/> resources.</returns>
public IAsyncEnumerable<IEnumerable<T>> BatchQueryAsync(
QueryDefinition query,
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents from the configured Cosmos container and returns a custom result.
/// </summary>
/// <typeparam name="TResult">The type used for the custom query result.</typeparam>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="partitionKey">Partition key of the resource.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="TResult"/> resources.</returns>
public IAsyncEnumerable<IEnumerable<TResult>> BatchQueryAsync<TResult>(
QueryDefinition query,
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents across partitions from the configured Cosmos container.
/// </summary>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="T"/> resources.</returns>
public IAsyncEnumerable<IEnumerable<T>> BatchCrossPartitionQueryAsync(
QueryDefinition query,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents across partitions from the configured Cosmos container and returns a custom result.
/// </summary>
/// <typeparam name="TResult">The type used for the custom query result.</typeparam>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used.</param>
/// <returns>An <see cref="IAsyncEnumerable<T>"/> over the requested <typeparamref name="TResult"/> resources.</returns>
public IAsyncEnumerable<IEnumerable<TResult>> BatchCrossPartitionQueryAsync<TResult>(
QueryDefinition query,
CancellationToken cancellationToken = default);
}
}