@@ -47,89 +47,89 @@ 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 }
57+
58+ // --- DATABASE EXISTS --- //
59+ let databaseExists < 'T > op =
60+ { CheckIfDatabaseExistsOp.Connection = op }
6361
6462 // --- INSERT --- //
6563
6664 let insertMany < 'T > ( values : 'T list ) op =
67- Insert { Connection = op; Values = values }
65+ { InsertOp. Connection = op; Values = values }
6866
6967 let insert < 'T > ( value : 'T ) op =
70- Insert { Connection = op; Values = [ value ] }
68+ { InsertOp. Connection = op; Values = [ value ] }
7169
7270 // --- INSERT --- //
7371
7472 let upsertMany < 'T > ( values : 'T list ) op =
75- Upsert { Connection = op; Values = values }
73+ { UpsertOp. Connection = op; Values = values }
7674
7775 let upsert < 'T > ( value : 'T ) op =
78- Upsert { Connection = op; Values = [ value ] }
76+ { UpsertOp. Connection = op; Values = [ value ] }
7977
8078 // --- UPDATE --- //
8179
8280 let update < 'T > id partitionKey ( updater : 'T -> 'T ) op =
83- Update
84- { Connection = op
85- Id = id
86- PartitionKey = partitionKey
87- Updater = updater }
88-
89- // --- DELETE --- //
90-
91- let delete < 'T > id partitionKey op =
92- Delete
93- { Connection = op
94- Id = id
95- PartitionKey = partitionKey }
81+ { UpdateOp.Connection = op
82+ Id = id
83+ PartitionKey = partitionKey
84+ Updater = updater }
85+
86+ // --- DELETE ITEM --- //
87+
88+ let deleteItem < 'T > id partitionKey op =
89+ { DeleteItemOp.Connection = op
90+ Id = id
91+ PartitionKey = partitionKey }
92+
93+ // --- GET CONTAINER PROPERTIES --- //
94+ let getContainerProperties op =
95+ { GetContainerPropertiesOp.Connection = op }
96+
97+ // --- CONTAINER EXISTS --- //
98+ let containerExists op =
99+ { CheckIfContainerExistsOp.Connection = op }
100+
101+ // --- DELETE CONTAINER --- //
102+
103+ let deleteContainer < 'T > op : DeleteContainerOp < 'T > =
104+ { DeleteContainerOp.Connection = op }
105+
106+ // --- DELETE CONTAINER IF EXISTS --- //
107+
108+ let deleteContainerIfExists op : DeleteContainerIfExistsOp =
109+ { DeleteContainerIfExistsOp.Connection = op }
96110
97111 // --- READ --- //
98112
99113 let read id partitionKey op =
100- Read
101- { Connection = op
102- Id = id
103- PartitionKey = partitionKey }
114+ { ReadOp.Connection = op
115+ Id = id
116+ PartitionKey = partitionKey }
104117
105118 // --- REPLACE --- //
106119
107120 let replace < 'T > ( item : 'T ) op =
108- Replace { Connection = op; Item = item }
121+ { ReplaceOp. Connection = op; Item = item }
109122
110123 // --- Execute --- //
111124
112125 let private getClient ( connInfo : ConnectionOperation ) = connInfo.GetClient()
113126
114127 let dispose ( connInfo : ConnectionOperation ) = ( connInfo :> IDisposable) .Dispose()
115128
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."
129+ let execBatchAsync < 'T > batchSize op =
130+ let queryOps = QueryRequestOptions()
131+ queryOps.MaxItemCount <- batchSize
132+ OperationHandling.execQueryBatch getClient op queryOps
133133
134134 // --- Access Cosmos APIs directly --- //
135135
@@ -233,3 +233,18 @@ module Cosmos =
233233 processor.Build()
234234 | None ->
235235 failwith " Unable to connect the change feed. Ensure the container and lease container info is all set"
236+
237+ type Cosmos =
238+ static member private getClient ( connInfo : ConnectionOperation ) = connInfo.GetClient()
239+ static member execAsync ( op : QueryOp < 'T >) = OperationHandling.execQuery Cosmos.getClient op
240+ static member execAsync op = OperationHandling.execCheckIfDatabaseExists Cosmos.getClient op
241+ static member execAsync op = OperationHandling.execInsert Cosmos.getClient op
242+ static member execAsync op = OperationHandling.execUpdate Cosmos.getClient op
243+ static member execAsync op = OperationHandling.execDeleteItem Cosmos.getClient op
244+ static member execAsync op = OperationHandling.execGetContainerProperties Cosmos.getClient op
245+ static member execAsync op = OperationHandling.execCheckIfContainerExists Cosmos.getClient op
246+ static member execAsync op = OperationHandling.execDeleteContainer Cosmos.getClient op
247+ static member execAsync op = OperationHandling.execDeleteContainerIfExists Cosmos.getClient op
248+ static member execAsync op = OperationHandling.execUpsert Cosmos.getClient op
249+ static member execAsync op = OperationHandling.execRead Cosmos.getClient op
250+ static member execAsync op = OperationHandling.execReplace Cosmos.getClient op
0 commit comments