@@ -47,89 +47,72 @@ module Cosmos =
4747 Query = None
4848 Parameters = [] }
4949
50- let query < 'T > query op : ContainerOperation < 'T > =
51- Query
52- { defaultQueryOp () with
53- Query = Some query
54- Connection = op }
50+ let query < 'T > query op : QueryOp < 'T > =
51+ { defaultQueryOp () with
52+ Query = Some query
53+ Connection = op }
5554
5655 let parameters arr op =
57- match op with
58- | Query q ->
59- Query
60- { q with
61- Parameters = q.Parameters @ arr }
62- | _ -> failwith " Only the Query discriminated union supports parameters"
56+ { op with QueryOp.Parameters = op.Parameters @ arr }
6357
6458 // --- INSERT --- //
6559
6660 let insertMany < 'T > ( values : 'T list ) op =
67- Insert { Connection = op; Values = values }
61+ { InsertOp. Connection = op; Values = values }
6862
6963 let insert < 'T > ( value : 'T ) op =
70- Insert { Connection = op; Values = [ value ] }
64+ { InsertOp. Connection = op; Values = [ value ] }
7165
7266 // --- INSERT --- //
7367
7468 let upsertMany < 'T > ( values : 'T list ) op =
75- Upsert { Connection = op; Values = values }
69+ { UpsertOp. Connection = op; Values = values }
7670
7771 let upsert < 'T > ( value : 'T ) op =
78- Upsert { Connection = op; Values = [ value ] }
72+ { UpsertOp. Connection = op; Values = [ value ] }
7973
8074 // --- UPDATE --- //
8175
8276 let update < 'T > id partitionKey ( updater : 'T -> 'T ) op =
83- Update
84- { Connection = op
85- Id = id
86- PartitionKey = partitionKey
87- Updater = updater }
77+ { UpdateOp.Connection = op
78+ Id = id
79+ PartitionKey = partitionKey
80+ Updater = updater }
8881
89- // --- DELETE --- //
82+ // --- DELETE ITEM --- //
9083
91- let delete < 'T > id partitionKey op =
92- Delete
93- { Connection = op
94- Id = id
95- PartitionKey = partitionKey }
84+ let deleteItem < 'T > id partitionKey op =
85+ { DeleteItemOp.Connection = op
86+ Id = id
87+ PartitionKey = partitionKey }
88+
89+ // --- DELETE CONTAINER --- //
90+
91+ let deleteContainer < 'T > op : DeleteContainerOp < 'T > =
92+ { DeleteContainerOp.Connection = op }
9693
9794 // --- READ --- //
9895
9996 let read id partitionKey op =
100- Read
101- { Connection = op
102- Id = id
103- PartitionKey = partitionKey }
97+ { ReadOp.Connection = op
98+ Id = id
99+ PartitionKey = partitionKey }
104100
105101 // --- REPLACE --- //
106102
107103 let replace < 'T > ( item : 'T ) op =
108- Replace { Connection = op; Item = item }
104+ { ReplaceOp. Connection = op; Item = item }
109105
110106 // --- Execute --- //
111107
112108 let private getClient ( connInfo : ConnectionOperation ) = connInfo.GetClient()
113109
114110 let dispose ( connInfo : ConnectionOperation ) = ( connInfo :> IDisposable) .Dispose()
115111
116- let execAsync < 'T > ( op : ContainerOperation < 'T >) =
117- match op with
118- | Query op -> OperationHandling.execQuery getClient op
119- | Insert op -> OperationHandling.execInsert getClient op
120- | Update op -> OperationHandling.execUpdate getClient op
121- | Delete op -> OperationHandling.execDelete getClient op
122- | Upsert op -> OperationHandling.execUpsert getClient op
123- | Read op -> OperationHandling.execRead getClient op
124- | Replace op -> OperationHandling.execReplace getClient op
125-
126- let execBatchAsync < 'T > batchSize ( op : ContainerOperation < 'T >) =
127- match op with
128- | Query op ->
129- let queryOps = QueryRequestOptions()
130- queryOps.MaxItemCount <- batchSize
131- OperationHandling.execQueryBatch getClient op queryOps
132- | _ -> failwith " Batch return operation only supported with query operations, use `execAsync` instead."
112+ let execBatchAsync < 'T > batchSize op =
113+ let queryOps = QueryRequestOptions()
114+ queryOps.MaxItemCount <- batchSize
115+ OperationHandling.execQueryBatch getClient op queryOps
133116
134117 // --- Access Cosmos APIs directly --- //
135118
@@ -233,3 +216,14 @@ module Cosmos =
233216 processor.Build()
234217 | None ->
235218 failwith " Unable to connect the change feed. Ensure the container and lease container info is all set"
219+
220+ type Cosmos =
221+ static member private getClient ( connInfo : ConnectionOperation ) = connInfo.GetClient()
222+ static member execAsync ( op : QueryOp < 'T >) = OperationHandling.execQuery Cosmos.getClient op
223+ static member execAsync op = OperationHandling.execInsert Cosmos.getClient op
224+ static member execAsync op = OperationHandling.execUpdate Cosmos.getClient op
225+ static member execAsync op = OperationHandling.execDeleteItem Cosmos.getClient op
226+ static member execAsync op = OperationHandling.execDeleteContainer Cosmos.getClient op
227+ static member execAsync op = OperationHandling.execUpsert Cosmos.getClient op
228+ static member execAsync op = OperationHandling.execRead Cosmos.getClient op
229+ static member execAsync op = OperationHandling.execReplace Cosmos.getClient op
0 commit comments