@@ -141,55 +141,6 @@ def read(self, populate_query_metrics=None, **kwargs):
141
141
142
142
return cast ('Dict[str, Any]' , self ._properties )
143
143
144
- @distributed_trace
145
- def create_if_not_exists ( # pylint: disable=redefined-builtin
146
- self ,
147
- populate_query_metrics = None , # type: Optional[bool]
148
- offer_throughput = None , # type: Optional[int]
149
- ** kwargs # type: Any
150
- ):
151
- # type: (...) -> DatabaseProxy
152
- """
153
- Create the database if it does not exist already.
154
-
155
- If the database already exists, it is returned.
156
-
157
- :param str session_token: Token for use with Session consistency.
158
- :param dict(str, str) initial_headers: Initial headers to be sent as part of the request.
159
- :param dict(str, str) access_condition: Conditions Associated with the request.
160
- :param bool populate_query_metrics: Enable returning query metrics in response headers.
161
- :param int offer_throughput: The provisioned throughput for this offer.
162
- :param dict(str, Any) request_options: Dictionary of additional properties to be used for the request.
163
- :param Callable response_hook: a callable invoked with the response metadata
164
- :returns: A DatabaseProxy instance representing the database.
165
- :rtype: ~azure.cosmos.database.DatabaseProxy
166
- :raise CosmosHttpResponseError: The database read or creation failed.
167
- """
168
- response_hook = kwargs .pop ('response_hook' , None )
169
- try :
170
- from .cosmos_client import CosmosClient
171
-
172
- database_link = CosmosClient ._get_database_link (self )
173
- self ._properties = self .client_connection .ReadDatabase (
174
- database_link , ** kwargs
175
- )
176
-
177
- if response_hook :
178
- response_hook (self .client_connection .last_response_headers , self ._properties )
179
-
180
- return self
181
- except CosmosResourceNotFoundError :
182
- request_options = build_options (kwargs )
183
- if populate_query_metrics is not None :
184
- request_options ["populateQueryMetrics" ] = populate_query_metrics
185
- if offer_throughput is not None :
186
- request_options ["offerThroughput" ] = offer_throughput
187
-
188
- result = self .client_connection .CreateDatabase (database = dict (id = self .id ), options = request_options , ** kwargs )
189
- if response_hook :
190
- response_hook (self .client_connection .last_response_headers )
191
- return DatabaseProxy (self .client_connection , id = result ["id" ], properties = result )
192
-
193
144
@distributed_trace
194
145
def create_container (
195
146
self ,
@@ -271,6 +222,62 @@ def create_container(
271
222
272
223
return ContainerProxy (self .client_connection , self .database_link , data ["id" ], properties = data )
273
224
225
+ @distributed_trace
226
+ def create_container_if_not_exists (
227
+ self ,
228
+ id , # type: str # pylint: disable=redefined-builtin
229
+ partition_key , # type: Any
230
+ indexing_policy = None , # type: Optional[Dict[str, Any]]
231
+ default_ttl = None , # type: Optional[int]
232
+ populate_query_metrics = None , # type: Optional[bool]
233
+ offer_throughput = None , # type: Optional[int]
234
+ unique_key_policy = None , # type: Optional[Dict[str, Any]]
235
+ conflict_resolution_policy = None , # type: Optional[Dict[str, Any]]
236
+ ** kwargs # type: Any
237
+ ):
238
+ # type: (...) -> ContainerProxy
239
+ """
240
+ Create the container if it does not exist already.
241
+
242
+ If the container already exists, it is returned.
243
+
244
+ :param id: ID (name) of container to read or create.
245
+ :param partition_key: The partition key to use for the container.
246
+ :param indexing_policy: The indexing policy to apply to the container.
247
+ :param default_ttl: Default time to live (TTL) for items in the container. If unspecified, items do not expire.
248
+ :param session_token: Token for use with Session consistency.
249
+ :param initial_headers: Initial headers to be sent as part of the request.
250
+ :param access_condition: Conditions Associated with the request.
251
+ :param populate_query_metrics: Enable returning query metrics in response headers.
252
+ :param offer_throughput: The provisioned throughput for this offer.
253
+ :param unique_key_policy: The unique key policy to apply to the container.
254
+ :param conflict_resolution_policy: The conflict resolution policy to apply to the container.
255
+ :param request_options: Dictionary of additional properties to be used for the request.
256
+ :param response_hook: a callable invoked with the response metadata
257
+ :returns: A `ContainerProxy` instance representing the container.
258
+ :raise CosmosHttpResponseError: The container read or creation failed.
259
+ :rtype: ~azure.cosmos.container.ContainerProxy
260
+ """
261
+
262
+ try :
263
+ container_proxy = self .get_container_client (id )
264
+ container_proxy .read (
265
+ populate_query_metrics = populate_query_metrics ,
266
+ ** kwargs
267
+ )
268
+ return container_proxy
269
+ except CosmosResourceNotFoundError :
270
+ return self .create_container (
271
+ id = id ,
272
+ partition_key = partition_key ,
273
+ indexing_policy = indexing_policy ,
274
+ default_ttl = default_ttl ,
275
+ populate_query_metrics = populate_query_metrics ,
276
+ offer_throughput = offer_throughput ,
277
+ unique_key_policy = unique_key_policy ,
278
+ conflict_resolution_policy = conflict_resolution_policy
279
+ )
280
+
274
281
@distributed_trace
275
282
def delete_container (
276
283
self ,
0 commit comments