Source file database_intf.ml
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
type 'a io = unit -> 'a
type batch_validation_error = Cosmos.Databases_core.batch_validation_error =
| Too_many_operations of int
| Mixed_patch_operations
| Empty_batch
type cosmos_error = Cosmos.Databases_core.Cosmos_error.t
module type S = sig
val get_code : Cohttp.Response.t -> int
val list_databases :
?timeout:float ->
unit ->
(int * Cosmos.Json_converter_t.list_databases, cosmos_error) result io
val create :
?timeout:float ->
string ->
(int * Cosmos.Json_converter_t.database option, cosmos_error) result io
val create_if_not_exists :
?timeout:float ->
string ->
(int * Cosmos.Json_converter_t.database option, cosmos_error) result io
val get :
?timeout:float ->
string ->
(int * Cosmos.Json_converter_t.database option, cosmos_error) result io
val delete : ?timeout:float -> string -> (int, cosmos_error) result io
module Collection : sig
val list :
?timeout:float ->
string ->
(int * Cosmos.Json_converter_t.list_collections, cosmos_error) result io
val create :
?indexing_policy:Cosmos.Json_converter_t.indexing_policy option ->
?offer_throughput:int ->
partition_key:Cosmos.Json_converter_t.create_partition_key ->
?timeout:float ->
string ->
string ->
(int * Cosmos.Json_converter_t.collection option, cosmos_error) result io
val create_if_not_exists :
?indexing_policy:Cosmos.Json_converter_t.indexing_policy option ->
?offer_throughput:int ->
partition_key:Cosmos.Json_converter_t.create_partition_key ->
?timeout:float ->
string ->
string ->
(int * Cosmos.Json_converter_t.collection option, cosmos_error) result io
val get :
?timeout:float ->
string ->
string ->
(int * Cosmos.Json_converter_t.collection option, cosmos_error) result io
val delete :
?timeout:float -> string -> string -> (int, cosmos_error) result io
module Document : sig
type indexing_directive = Include | Exclude
val create :
?is_upsert:bool ->
?indexing_directive:indexing_directive ->
partition_key:string ->
?timeout:float ->
string ->
string ->
string ->
(int * Cosmos.Json_converter_t.collection option, cosmos_error) result
io
val create_multiple :
?is_upsert:bool ->
?indexing_directive:indexing_directive ->
?timeout:float ->
?chunk_size:int ->
string ->
string ->
(string * string) list ->
(int * Cosmos.Json_converter_t.collection option, cosmos_error) result
list
io
type list_result_meta_data = {
rid : string;
self : string;
etag : string;
ts : int;
attachments : string;
}
type list_result = {
rid : string;
documents : (string * list_result_meta_data option) list;
count : int;
}
val list :
?max_item_count:int ->
?continuation:string ->
?consistency_level:string ->
?session_token:string ->
?a_im:bool ->
?if_none_match:string ->
?partition_key_range_id:string ->
?timeout:float ->
string ->
string ->
(int * Response_headers.t * list_result, cosmos_error) result io
(** [list] is the legacy document-feed operation. For change-feed
consumers, use [Change_feed.read], whose [304] result is explicit. *)
type consistency_level = Strong | Bounded | Session | Eventual
val string_of_consistency_level : consistency_level -> string
val get :
?if_none_match:string ->
partition_key:string ->
?consistency_level:consistency_level ->
?session_token:string ->
?timeout:float ->
string ->
string ->
string ->
(int * string, cosmos_error) result io
val replace :
?indexing_directive:indexing_directive ->
partition_key:string ->
?if_match:string ->
?timeout:float ->
string ->
string ->
string ->
string ->
(int * string, cosmos_error) result io
val delete :
partition_key:string ->
?timeout:float ->
string ->
string ->
string ->
(int, cosmos_error) result io
val delete_multiple :
partition_key:string ->
?timeout:float ->
?chunk_size:int ->
string ->
string ->
string list ->
(int, cosmos_error) result list io
val query :
?max_item_count:int ->
?continuation:string ->
?consistency_level:string ->
?session_token:string ->
?is_partition:bool ->
?partition_key:string ->
?timeout:float ->
string ->
string ->
Cosmos.Json_converter_t.query ->
(int * Response_headers.t * list_result, cosmos_error) result io
end
module Partition_key_range : sig
val list :
?max_item_count:int ->
?continuation:string ->
?timeout:float ->
string ->
string ->
( int
* Response_headers.t
* Cosmos.Json_converter_t.list_partition_key_ranges,
cosmos_error )
result
io
(** Partition-key ranges can be enumerated for caller-managed fan-out. *)
val ids :
?timeout:float ->
string ->
string ->
(int * string list, cosmos_error) result io
end
module Change_feed : sig
(** Pull-model latest-version change feed operations. *)
module Mode : sig
type t = Latest_version
val string_of : t -> string
end
module Start_from : sig
type t =
| Beginning
| Now
| Point_in_time of float
| Continuation of string
val string_of : t -> string
end
module Scope : sig
type t =
| Container
| Partition_key of string
| Partition_key_range of string
val string_of : t -> string
end
type page = {
rid : string;
documents : (string * Document.list_result_meta_data option) list;
count : int;
continuation : string;
has_more_pages : bool;
(** Presence of [x-ms-continuation]; Azure may omit it for change
feed. Continue with [Continuation continuation] until 304, as
[drain] does. *)
session_token : string option;
}
type drain_result = {
pages : page list;
checkpoint : string;
caught_up : bool;
}
val read :
?mode:Mode.t ->
?start_from:Start_from.t ->
?scope:Scope.t ->
?max_item_count:int ->
?session_token:string ->
?timeout:float ->
string ->
string ->
(int * Response_headers.t * page option, cosmos_error) result io
(** [read db coll] reads one page. [Ok (304, _, None)] means the feed is
idle, not that the request failed. Persist [page.continuation] and
resume with [Start_from.Continuation]. A supplied timeout applies
independently to each request attempt; exhausted 429 retries are
reported as [Timeout_error]. *)
val is_partition_split : cosmos_error -> bool
val drain :
?mode:Mode.t ->
?start_from:Start_from.t ->
?scope:Scope.t ->
?max_item_count:int ->
?max_pages:int ->
?timeout:float ->
string ->
string ->
(drain_result, cosmos_error) result io
val fold :
?mode:Mode.t ->
?start_from:Start_from.t ->
?scope:Scope.t ->
?max_item_count:int ->
?poll_interval:float ->
?max_polls:int ->
?timeout:float ->
string ->
string ->
init:'acc ->
f:('acc -> page -> ('acc, string) result io) ->
('acc * string, cosmos_error) result io
end
module Batch : sig
type operation =
| Create of {
if_match : string option;
if_none_match : string option;
body : string;
}
| Upsert of {
if_match : string option;
if_none_match : string option;
body : string;
}
| Read of {
id : string;
if_match : string option;
if_none_match : string option;
}
| Delete of {
id : string;
if_match : string option;
if_none_match : string option;
}
| Replace of {
id : string;
if_match : string option;
if_none_match : string option;
body : string;
}
| Patch of {
id : string;
if_match : string option;
patch_op : patch_operation;
}
and patch_operation =
| Add of { path : string; value : string }
| Set of { path : string; value : string }
| ReplacePath of { path : string; value : string }
| Remove of { path : string }
| Increment of { path : string; value : int }
type operation_result = {
status_code : int;
request_charge : float;
etag : string option;
resource_body : string option;
}
type batch_result = {
outcomes : operation_result list;
total_request_charge : float;
}
type validation_error = batch_validation_error =
| Too_many_operations of int
| Mixed_patch_operations
| Empty_batch
val validate : operation list -> (unit, validation_error) result
val execute :
?timeout:float ->
?atomic:bool ->
partition_key:string ->
string ->
string ->
operation list ->
(batch_result, cosmos_error) result io
end
module Batch_builder : sig
type t
val empty : t
val add_create :
?if_match:string -> ?if_none_match:string -> body:string -> t -> t
val add_upsert :
?if_match:string -> ?if_none_match:string -> body:string -> t -> t
val add_read :
?if_match:string -> ?if_none_match:string -> id:string -> t -> t
val add_delete :
?if_match:string -> ?if_none_match:string -> id:string -> t -> t
val add_replace :
?if_match:string ->
?if_none_match:string ->
id:string ->
body:string ->
t ->
t
val add_patch :
?if_match:string ->
id:string ->
patch_op:Batch.patch_operation ->
t ->
t
val build : t -> (Batch.operation list, Batch.validation_error) result
val to_operations : t -> Batch.operation list
val length : t -> int
end
end
module User : sig
val create :
?timeout:float ->
string ->
string ->
(int * Cosmos.Json_converter_t.user, cosmos_error) result io
val list :
?timeout:float ->
string ->
(int * Cosmos.Json_converter_t.list_users, cosmos_error) result io
val get :
?timeout:float ->
string ->
string ->
(int * Cosmos.Json_converter_t.user, cosmos_error) result io
val replace :
?timeout:float ->
string ->
string ->
string ->
(int * Cosmos.Json_converter_t.user, cosmos_error) result io
val delete :
?timeout:float -> string -> string -> (int, cosmos_error) result io
end
module Permission : sig
type permission_mode = Read | All
val create :
?timeout:float ->
?expiry_seconds:int ->
dbname:string ->
user_name:string ->
coll_name:string ->
permission_mode ->
permission_name:string ->
(int * Cosmos.Json_converter_t.permission, cosmos_error) result io
(** [expiry_seconds] sets [x-ms-documentdb-expiry-seconds], the validity of
the returned resource token (1..18000, default 3600). *)
val list :
?timeout:float ->
dbname:string ->
user_name:string ->
unit ->
(int * Cosmos.Json_converter_t.list_permissions, cosmos_error) result io
val get :
?timeout:float ->
?expiry_seconds:int ->
dbname:string ->
user_name:string ->
permission_name:string ->
unit ->
(int * Cosmos.Json_converter_t.permission, cosmos_error) result io
val replace :
?timeout:float ->
?expiry_seconds:int ->
dbname:string ->
user_name:string ->
coll_name:string ->
permission_mode ->
permission_name:string ->
(int * Cosmos.Json_converter_t.permission, cosmos_error) result io
val delete :
?timeout:float ->
dbname:string ->
user_name:string ->
permission_name:string ->
unit ->
(int, cosmos_error) result io
end
module Offer : sig
module Throughput : sig
type t = Manual of int | Autoscale of { max_throughput : int }
val to_content : t -> Cosmos.Json_converter_t.offer_content
val of_content : Cosmos.Json_converter_t.offer_content -> t option
val string_of : t -> string
end
val list :
?timeout:float ->
unit ->
(int * Cosmos.Json_converter_t.list_offers, cosmos_error) result io
(** [list ()] returns all throughput offers in the account. Requires
master-key authentication. *)
val get :
?timeout:float ->
string ->
(int * Cosmos.Json_converter_t.offer, cosmos_error) result io
(** [get offer_rid] returns the offer identified by [offer_rid]. Requires
master-key authentication. *)
val query :
?max_item_count:int ->
?continuation:string ->
?timeout:float ->
Cosmos.Json_converter_t.query ->
( int * Response_headers.t * Cosmos.Json_converter_t.list_offers,
cosmos_error )
result
io
val replace :
?migrate:[ `To_autoscale | `To_manual ] ->
?timeout:float ->
Cosmos.Json_converter_t.offer ->
Throughput.t ->
(int * Cosmos.Json_converter_t.offer, cosmos_error) result io
val get_for_collection :
?timeout:float ->
string ->
string ->
(int * Cosmos.Json_converter_t.offer option, cosmos_error) result io
val get_for_database :
?timeout:float ->
string ->
(int * Cosmos.Json_converter_t.offer option, cosmos_error) result io
val get_throughput :
?timeout:float ->
string ->
string ->
(int * Throughput.t option, cosmos_error) result io
(** [get_throughput dbname coll_name] returns the collection's provisioned
throughput, or [None] for serverless accounts. Requires master-key
authentication. *)
val set_throughput :
?migrate:[ `To_autoscale | `To_manual ] ->
?timeout:float ->
string ->
string ->
Throughput.t ->
(int * Cosmos.Json_converter_t.offer, cosmos_error) result io
(** [set_throughput dbname coll_name throughput] changes the collection's
provisioned throughput. Requires master-key authentication and is
unavailable for serverless accounts. *)
end
end