-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathICouchDatabase.cs
334 lines (300 loc) · 21.4 KB
/
ICouchDatabase.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CouchDB.Driver.ChangesFeed;
using CouchDB.Driver.ChangesFeed.Responses;
using CouchDB.Driver.Indexes;
using CouchDB.Driver.Local;
using CouchDB.Driver.DatabaseApiMethodOptions;
using CouchDB.Driver.Security;
using CouchDB.Driver.Types;
using CouchDB.Driver.Views;
using Flurl.Http;
namespace CouchDB.Driver
{
/// <summary>
/// Represent a database.
/// </summary>
/// <typeparam name="TSource">The type of the document.</typeparam>
public interface ICouchDatabase<TSource>: IOrderedQueryable<TSource>
where TSource : CouchDocument
{
/// <summary>
/// Finds the document with the given ID. If no document is found, then null is returned.
/// </summary>
/// <param name="docId">The document ID.</param>
/// <param name="withConflicts">Set if conflicts array should be included.</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 the element found, or null.</returns>
Task<TSource?> FindAsync(string docId, bool withConflicts = false, CancellationToken cancellationToken = default);
/// <summary>
/// Finds the document with the given ID. If no document is found, then null is returned.
/// </summary>
/// <param name="docId">The document ID.</param>
/// <param name="options">Set of options available for GET /{db}/{docid}</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 the element found, or null</returns>
Task<TSource?> FindAsync(string docId, FindOptions options, CancellationToken cancellationToken = default);
/// <summary>
/// Finds all documents matching the MangoQuery.
/// </summary>
/// <param name="mangoQueryJson">The JSON representing the Mango query.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <retuns>A task that represents the asynchronous operation. The task result contains a <see cref="List{TSource}"/> that contains elements from the database.</retuns>
Task<List<TSource>> QueryAsync(string mangoQueryJson, CancellationToken cancellationToken = default);
/// <summary>
/// Finds all documents matching the MangoQuery.
/// </summary>
/// <param name="mangoQuery">The object representing the Mango query.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <retuns>A task that represents the asynchronous operation. The task result contains a <see cref="List{TSource}"/> that contains elements from the database.</retuns>
Task<List<TSource>> QueryAsync(object mangoQuery, CancellationToken cancellationToken = default);
/// <summary>
/// Finds all documents with given IDs.
/// </summary>
/// <param name="docIds">The collection of documents IDs.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <retuns>A task that represents the asynchronous operation. The task result contains a <see cref="List{TSource}"/> that contains elements from the database.</retuns>
Task<List<TSource>> FindManyAsync(IReadOnlyCollection<string> docIds, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new document and returns it.
/// </summary>
/// <param name="document">The document to create.</param>
/// <param name="batch">Stores document in batch mode.</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 the element created.</returns>
Task<TSource> AddAsync(TSource document, bool batch = false, CancellationToken cancellationToken = default);
/// <summary>
/// Creates a new document and returns it.
/// </summary>
/// <param name="document">The document to create.</param>
/// <param name="options">Set of options available for both PUT /{db}/{docid} and POST /{db}</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 the element created.</returns>
Task<TSource> AddAsync(TSource document, AddOptions options, CancellationToken cancellationToken = default);
/// <summary>
/// Creates or updates the document with the given ID.
/// </summary>
/// <param name="document">The document to create or update</param>
/// <param name="batch">Stores document in batch mode.</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 the element created or updated.</returns>
Task<TSource> AddOrUpdateAsync(TSource document, bool batch = false, CancellationToken cancellationToken = default);
/// <summary>
/// Creates or updates the document with the given ID.
/// </summary>
/// <param name="document">The document to create or update</param>
/// <param name="options">Set of options available for PUT /{db}/{docid}</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 the element created or updated.</returns>
Task<TSource> AddOrUpdateAsync(TSource document, AddOrUpdateOptions options, CancellationToken cancellationToken = default);
/// <summary>
/// Deletes the document with the given ID.
/// </summary>
/// <param name="document">The document to delete.</param>
/// <param name="batch">Stores document in batch mode.</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.</returns>
Task RemoveAsync(TSource document, bool batch = false, CancellationToken cancellationToken = default);
/// <summary>
/// Creates or updates a sequence of documents based on their IDs.
/// </summary>
/// <param name="documents">Documents to create or update</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 the elements created or updated.</returns>
Task<IEnumerable<TSource>> AddOrUpdateRangeAsync(IList<TSource> documents, CancellationToken cancellationToken = default);
/// <summary>
/// Delete multiple documents based on their ID and revision.
/// </summary>
/// <param name="documents">The documents to delete.</param>
/// <param name="cancellationToken"> <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
Task DeleteRangeAsync(IEnumerable<TSource> documents, CancellationToken cancellationToken = default);
/// <summary>
/// Delete multiple documents based on their ID and revision.
/// </summary>
/// <param name="documentIds">Documents to delete</param>
/// <param name="cancellationToken"> <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A task that represents the asynchronous operation.</returns>
Task DeleteRangeAsync(IEnumerable<DocumentId> documentIds, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified view function from the specified design document.
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="design">The design to use.</param>
/// <param name="view">The view to use.</param>
/// <param name="options">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 of <see cref="CouchView{TKey, TValue, TSource}"/>.</returns>
Task<List<CouchView<TKey, TValue, TSource>>> GetViewAsync<TKey, TValue>(string design, string view,
CouchViewOptions<TKey>? options = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified view function from the specified design document.
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="design">The design to use.</param>
/// <param name="view">The view to use.</param>
/// <param name="options">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 the <see cref="CouchViewList{TKey, TSource, TView}"/>.</returns>
Task<CouchViewList<TKey, TValue, TSource>> GetDetailedViewAsync<TKey, TValue>(string design, string view,
CouchViewOptions<TKey>? options = null, CancellationToken cancellationToken = default);
/// <summary>
/// Executes the specified view function from the specified design document using
/// the queries endpoint. This returns one result for each query option in the provided sequence.
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="design">The design to use.</param>
/// <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 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
/// the queries endpoint. This returns one result for each query option in the provided sequence.
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TValue">The type of the value.</typeparam>
/// <param name="design">The design to use.</param>
/// <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 <see cref="CouchViewList{TKey, TSource, TView}"/> for each query.</returns>
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).
///
/// Commits any recent changes to the specified database to disk. You should call this if you want to ensure that recent changes have been flushed.
/// This function is likely not required, assuming you have the recommended configuration setting of delayed_commits=false, which requires CouchDB to ensure changes are written to disk before a 200 or similar result is returned.
/// </summary>
/// <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.</returns>
Task EnsureFullCommitAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Returns a sorted list of changes made to documents in the database.
/// </summary>
/// <remarks>
/// Only the most recent change for a given document is guaranteed to be provided.
/// </remarks>
/// <param name="options">Options to apply to the request.</param>
/// <param name="filter">A filter to apply to the result.</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 the feed change.</returns>
Task<ChangesFeedResponse<TSource>> GetChangesAsync(ChangesFeedOptions? options = null,
ChangesFeedFilter? filter = null, CancellationToken cancellationToken = default);
/// <summary>
/// Returns changes as they happen. A continuous feed stays open and connected to the database until explicitly closed.
/// </summary>
/// <remarks>
/// To stop receiving changes call <c>Cancel()</c> on the <c>CancellationTokenSource</c> used to create the <c>CancellationToken</c>.
/// </remarks>
/// <param name="options">Options to apply to the request.</param>
/// <param name="filter">A filter to apply to the result.</param>
/// <param name="cancellationToken">A cancellation token to stop receiving changes.</param>
/// <returns>A IAsyncEnumerable that represents the asynchronous operation. The task result contains the feed change.</returns>
IAsyncEnumerable<ChangesFeedResponseResult<TSource>> GetContinuousChangesAsync(
ChangesFeedOptions? options, ChangesFeedFilter? filter,
CancellationToken cancellationToken);
/// <summary>
/// Gets the list of indexes in the database.
/// </summary>
/// <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 the list of indexes.</returns>
Task<List<IndexInfo>> GetIndexesAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Creates an index for the current database with the given configuration.
/// </summary>
/// <param name="name">The name of the index.</param>
/// <param name="indexBuilderAction">The action to configure the index builder.</param>
/// <param name="options">The index options.</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 the ID of the design document.</returns>
Task<string> CreateIndexAsync(string name, Action<IIndexBuilder<TSource>> indexBuilderAction,
IndexOptions? options = null,
CancellationToken cancellationToken = default);
/// <summary>
/// Deletes a specific index.
/// </summary>
/// <param name="designDocument">The design document name.</param>
/// <param name="name">The index name.</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.</returns>
Task DeleteIndexAsync(string designDocument, string name, CancellationToken cancellationToken = default);
/// <summary>
/// Deletes a specific index.
/// </summary>
/// <param name="indexInfo">The index info.</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.</returns>
Task DeleteIndexAsync(IndexInfo indexInfo, CancellationToken cancellationToken = default);
/// <summary>
/// Asynchronously downloads a specific attachment.
/// </summary>
/// <param name="attachment">The attachment to download.</param>
/// <param name="localFolderPath">Path of local folder where file is to be downloaded.</param>
/// <param name="localFileName">Name of local file. If not specified, the source filename (from Content-Dispostion header, or last segment of the URL) is used.</param>
/// <param name="bufferSize">Buffer size in bytes. Default is 4096.</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 the path of the download file.</returns>
Task<string> DownloadAttachmentAsync(CouchAttachment attachment, string localFolderPath,
string? localFileName = null, int bufferSize = 4096, CancellationToken cancellationToken = default);
/// <summary>
/// Asynchronously downloads a specific attachment as stream.
/// </summary>
/// <param name="attachment">The attachment to download.</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 of the file stream.</returns>
Task<Stream> DownloadAttachmentAsStreamAsync(CouchAttachment attachment, CancellationToken cancellationToken = default);
/// <summary>
/// Requests compaction of the specified database.
/// </summary>
/// <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.</returns>
Task CompactAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets information about the specified database.
/// </summary>
/// <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 the database information.</returns>
Task<CouchDatabaseInfo> GetInfoAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Gets the revision limit for the specified database.
/// </summary>
/// <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 the database information.</returns>
Task<int> GetRevisionLimitAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Sets the revision limit for the specified database.
/// </summary>
/// <param name="limit">The limit to set.</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 the database information.</returns>
Task SetRevisionLimitAsync(int limit, CancellationToken cancellationToken = default);
/// <summary>
/// Get an empty request that targets the current database.
/// </summary>
/// <returns>A Flurl request.</returns>
IFlurlRequest NewRequest();
/// <summary>
/// The database name.
/// </summary>
string Database { get; }
/// <summary>
/// Section to handle security operations.
/// </summary>
public ICouchSecurity Security { get; }
/// <summary>
/// Access local documents operations.
/// </summary>
public ILocalDocuments LocalDocuments { get; }
}
}