-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathICosmosReader.cs
308 lines (286 loc) · 17.9 KB
/
ICosmosReader.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos;
namespace Atc.Cosmos
{
/// <summary>
/// Represents a reader that can read Cosmos resources.
/// </summary>
/// <typeparam name="T">
/// The type of <see cref="ICosmosResource"/>
/// to be read by this reader.
/// </typeparam>
public interface ICosmosReader<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 from the configured Cosmos container using IQueryable.
/// </summary>
/// <typeparam name="TResult">The type of the query result.</typeparam>
/// <param name="queryBuilder">Query builder. Should return IQueryable corresponding to desired Cosmos query.</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<TResult> QueryAsync<TResult>(
Func<IQueryable<T>, IQueryable<TResult>> queryBuilder,
string partitionKey,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents from the configured Cosmos container using pagination.
/// </summary>
/// <param name="query">Cosmos query to execute.</param>
/// <param name="partitionKey">Partition key of the resource.</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>> PagedQueryAsync(
QueryDefinition query,
string partitionKey,
int? pageSize,
string? continuationToken = default,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents 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="partitionKey">Partition key of the resource.</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>> PagedQueryAsync<TResult>(
QueryDefinition query,
string partitionKey,
int? pageSize,
string? continuationToken = default,
CancellationToken cancellationToken = default);
/// <summary>
/// Query documents from the configured Cosmos container using IQueryable and pagination.
/// </summary>
/// <typeparam name="TResult">The type of the query result.</typeparam>
/// <param name="queryBuilder">Query builder. Should return IQueryable corresponding to desired Cosmos query.</param>
/// <param name="partitionKey">Partition key of the resource.</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>> PagedQueryAsync<TResult>(
Func<IQueryable<T>, IQueryable<TResult>> queryBuilder,
string partitionKey,
int? pageSize,
string? continuationToken = default,
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 IQueryable.
/// </summary>
/// <typeparam name="TResult">The type of the query result.</typeparam>
/// <param name="queryBuilder">Query builder. Should return IQueryable corresponding to desired Cosmos query.</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>(
Func<IQueryable<T>, IQueryable<TResult>> queryBuilder,
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>
/// Query documents across partitions from the configured Cosmos container using IQueryable and pagination.
/// </summary>
/// <typeparam name="TResult">The type of the query result.</typeparam>
/// <param name="queryBuilder">Query builder. Should return IQueryable corresponding to desired Cosmos query.</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>(
Func<IQueryable<T>, IQueryable<TResult>> queryBuilder,
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 from the configured Cosmos container using IQueryable and returns results in batches.
/// </summary>
/// <typeparam name="TResult">The type of the query result.</typeparam>
/// <param name="queryBuilder">Query builder. Should return IQueryable corresponding to desired Cosmos query.</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>(
Func<IQueryable<T>, IQueryable<TResult>> queryBuilder,
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);
/// <summary>
/// Query documents across partitions from the configured Cosmos container using IQueryable and returns a results in batches.
/// </summary>
/// <typeparam name="TResult">The type of the query result.</typeparam>
/// <param name="queryBuilder">Query builder. Should return IQueryable corresponding to desired Cosmos query.</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>(
Func<IQueryable<T>, IQueryable<TResult>> queryBuilder,
CancellationToken cancellationToken = default);
}
}