Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 74 additions & 77 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/_container.py

Large diffs are not rendered by default.

96 changes: 52 additions & 44 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""

from typing import Any, Dict, List, Optional, Union, cast, Mapping, Iterable, Callable
import warnings
from azure.core.async_paging import AsyncItemPaged
from azure.core.credentials import TokenCredential
from azure.core.credentials_async import AsyncTokenCredential
Expand Down Expand Up @@ -245,10 +246,7 @@ async def create_database(
id: str,
*,
offer_throughput: Optional[Union[int, ThroughputProperties]] = None,
session_token: Optional[str] = None,
initial_headers: Optional[Dict[str, str]] = None,
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
**kwargs: Any
) -> DatabaseProxy:
"""
Expand All @@ -257,12 +255,7 @@ async def create_database(
:param str id: ID (name) of the database to create.
:keyword offer_throughput: The provisioned throughput for this offer.
:paramtype offer_throughput: Union[int, ~azure.cosmos.ThroughputProperties]
:keyword str session_token: Token for use with Session consistency.
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
:keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource
has changed, and act according to the condition specified by the `match_condition` parameter.
:keyword match_condition: The match condition to use upon the etag.
:paramtype match_condition: ~azure.core.MatchConditions
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], None]
:raises ~azure.cosmos.exceptions.CosmosResourceExistsError: Database with the given ID already exists.
Expand All @@ -279,14 +272,23 @@ async def create_database(
:caption: Create a database in the Cosmos DB account:
:name: create_database
"""
session_token = kwargs.get('session_token')
if session_token is not None:
kwargs["session_token"] = session_token
if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
warnings.warn(
"The 'session_token' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
etag = kwargs.get('etag')
if etag is not None:
kwargs["etag"] = etag
warnings.warn(
"The 'etag' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
match_condition = kwargs.get('match_condition')
if match_condition is not None:
kwargs["match_condition"] = match_condition
warnings.warn(
"The 'match_condition' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
request_options = _build_options(kwargs)
_set_throughput_options(offer=offer_throughput, request_options=request_options)

Expand All @@ -299,10 +301,7 @@ async def create_database_if_not_exists( # pylint: disable=redefined-builtin
id: str,
*,
offer_throughput: Optional[Union[int, ThroughputProperties]] = None,
session_token: Optional[str] = None,
initial_headers: Optional[Dict[str, str]] = None,
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
**kwargs: Any
) -> DatabaseProxy:
"""
Expand All @@ -317,26 +316,30 @@ async def create_database_if_not_exists( # pylint: disable=redefined-builtin
:param str id: ID (name) of the database to read or create.
:keyword offer_throughput: The provisioned throughput for this offer.
:paramtype offer_throughput: Union[int, ~azure.cosmos.ThroughputProperties]
:keyword str session_token: Token for use with Session consistency.
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
:keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource
has changed, and act according to the condition specified by the `match_condition` parameter.
:keyword match_condition: The match condition to use upon the etag.
:paramtype match_condition: ~azure.core.MatchConditions
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], None]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The database read or creation failed.
:returns: A DatabaseProxy instance representing the database.
:rtype: ~azure.cosmos.DatabaseProxy
"""
session_token = kwargs.get('session_token')
if session_token is not None:
kwargs["session_token"] = session_token
if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
warnings.warn(
"The 'session_token' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
etag = kwargs.get('etag')
if etag is not None:
kwargs["etag"] = etag
warnings.warn(
"The 'etag' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
match_condition = kwargs.get('match_condition')
if match_condition is not None:
kwargs["match_condition"] = match_condition
warnings.warn(
"The 'match_condition' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
try:
database_proxy = self.get_database_client(id)
await database_proxy.read(**kwargs)
Expand Down Expand Up @@ -370,7 +373,6 @@ def list_databases(
self,
*,
max_item_count: Optional[int] = None,
session_token: Optional[str] = None,
initial_headers: Optional[Dict[str, str]] = None,
response_hook: Optional[Callable[[Mapping[str, Any]], None]] = None,
**kwargs: Any
Expand All @@ -385,8 +387,11 @@ def list_databases(
:returns: An AsyncItemPaged of database properties (dicts).
:rtype: AsyncItemPaged[Dict[str, str]]
"""
session_token = kwargs.pop('session_token', None)
if session_token is not None:
kwargs["session_token"] = session_token
warnings.warn(
"The 'session_token' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
feed_options = _build_options(kwargs)
Expand All @@ -405,7 +410,6 @@ def query_databases(
*,
parameters: Optional[List[Dict[str, Any]]] = None,
max_item_count: Optional[int] = None,
session_token: Optional[str] = None,
initial_headers: Optional[Dict[str, str]] = None,
response_hook: Optional[Callable[[Mapping[str, Any]], None]] = None,
**kwargs: Any
Expand All @@ -424,8 +428,11 @@ def query_databases(
:returns: An AsyncItemPaged of database properties (dicts).
:rtype: AsyncItemPaged[Dict[str, str]]
"""
session_token = kwargs.get('session_token')
if session_token is not None:
kwargs["session_token"] = session_token
warnings.warn(
"The 'session_token' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
feed_options = _build_options(kwargs)
Expand All @@ -445,10 +452,7 @@ async def delete_database(
self,
database: Union[str, DatabaseProxy, Dict[str, Any]],
*,
session_token: Optional[str] = None,
initial_headers: Optional[Dict[str, str]] = None,
etag: Optional[str] = None,
match_condition: Optional[MatchConditions] = None,
response_hook: Optional[Callable[[Mapping[str, Any]], None]] = None,
**kwargs: Any
) -> None:
Expand All @@ -457,27 +461,31 @@ async def delete_database(
:param database: The ID (name), dict representing the properties, or :class:`DatabaseProxy`
instance of the database to delete.
:type database: Union[str, ~azure.cosmos.DatabaseProxy, Dict[str, Any]]
:keyword str session_token: Token for use with Session consistency.
:keyword dict[str, str] initial_headers: Initial headers to be sent as part of the request.
:keyword str etag: An ETag value, or the wildcard character (*). Used to check if the resource
has changed, and act according to the condition specified by the `match_condition` parameter.
:keyword match_condition: The match condition to use upon the etag.
:paramtype match_condition: ~azure.core.MatchConditions
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Mapping[str, Any]], None]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the database couldn't be deleted.
:rtype: None
"""
session_token = kwargs.get('session_token')
if session_token is not None:
kwargs["session_token"] = session_token
if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
warnings.warn(
"The 'session_token' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
etag = kwargs.get('etag')
if etag is not None:
kwargs["etag"] = etag
warnings.warn(
"The 'etag' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)
match_condition = kwargs.get('match_condition')
if match_condition is not None:
kwargs["match_condition"] = match_condition
request_options = _build_options(kwargs)
warnings.warn(
"The 'match_condition' flag does not apply to this method and will be removed in the future.",
DeprecationWarning)

if initial_headers is not None:
kwargs["initial_headers"] = initial_headers
request_options = _build_options(kwargs)
database_link = _get_database_link(database)
await self.client_connection.DeleteDatabase(database_link, options=request_options, **kwargs)
if response_hook:
Expand Down
Loading