|
| 1 | +import asyncio |
1 | 2 | from azure.cosmos import exceptions, CosmosClient, PartitionKey
|
2 | 3 | from azure.cosmos.aio import CosmosClient
|
3 | 4 |
|
@@ -37,7 +38,7 @@ async def examples_async():
|
37 | 38 | try:
|
38 | 39 | database = await client.create_database(id=database_name)
|
39 | 40 | except exceptions.CosmosResourceExistsError:
|
40 |
| - database = client.get_database_client(database_id=database_name) |
| 41 | + database = client.get_database_client(database=database_name) |
41 | 42 | # [END create_database]
|
42 | 43 |
|
43 | 44 | # Create a container, handling the exception if a container with the
|
@@ -76,7 +77,7 @@ async def examples_async():
|
76 | 77 |
|
77 | 78 | # [START list_containers]
|
78 | 79 | database = client.get_database_client(database_name)
|
79 |
| - for container in database.list_containers(): |
| 80 | + async for container in database.list_containers(): |
80 | 81 | print("Container ID: {}".format(container['id']))
|
81 | 82 | # [END list_containers]
|
82 | 83 |
|
@@ -155,8 +156,16 @@ async def examples_async():
|
155 | 156 | # [START create_user]
|
156 | 157 | try:
|
157 | 158 | await database.create_user(dict(id="Walter Harp"))
|
| 159 | + print("Created user Walter Harp.") |
158 | 160 | except exceptions.CosmosResourceExistsError:
|
159 | 161 | print("A user with that ID already exists.")
|
160 | 162 | except exceptions.CosmosHttpResponseError as failure:
|
161 | 163 | print("Failed to create user. Status code:{}".format(failure.status_code))
|
162 | 164 | # [END create_user]
|
| 165 | + |
| 166 | + await client.delete_database(database_name) |
| 167 | + print("Sample done running!") |
| 168 | + |
| 169 | +if __name__ == "__main__": |
| 170 | + loop = asyncio.get_event_loop() |
| 171 | + loop.run_until_complete(examples_async()) |
0 commit comments