Skip to content

Commit

Permalink
Merge pull request #5 from Azure-Samples/seesharprun-patch-1
Browse files Browse the repository at this point in the history
Rename snippets
  • Loading branch information
seesharprun authored Oct 11, 2023
2 parents a2c9b5d + 6a45db9 commit c0524ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
23 changes: 13 additions & 10 deletions src/web/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,20 @@

await WriteToConsoleAync("Current Status:\tStarting...");

// <get-database>
// <get_database>
Database database = client.GetDatabase("cosmicworks");
// </get-database>
// </get_database>
database = await database.ReadAsync();
await WriteToConsoleAync($"Get database:\t{database.Id}");

// <get-container>
// <get_container>
Container container = database.GetContainer("products");
// </get-container>
// </get_container>
container = await container.ReadContainerAsync();
await WriteToConsoleAync($"Get container:\t{container.Id}");

{
// <create-item>
// <create_item>
Product item = new(
id: "68719518391",
category: "gear-surf-surfboards",
Expand All @@ -63,7 +65,7 @@
item: item,
partitionKey: new PartitionKey("gear-surf-surfboards")
);
// </create-item>
// </create_item>
await WriteToConsoleAync($"Upserted item:\t{response.Resource}");
await WriteToConsoleAync($"Status code:\t{response.StatusCode}");
await WriteToConsoleAync($"Request charge:\t{response.RequestCharge:0.00}");
Expand All @@ -89,20 +91,20 @@
}

{
// <read-item>
// <read_item>
ItemResponse<Product> response = await container.ReadItemAsync<Product>(
id: "68719518391",
partitionKey: new PartitionKey("gear-surf-surfboards")
);
// </read-item>
// </read_item>
await WriteToConsoleAync($"Read item id:\t{response.Resource.id}");
await WriteToConsoleAync($"Read item:\t{response.Resource}");
await WriteToConsoleAync($"Status code:\t{response.StatusCode}");
await WriteToConsoleAync($"Request charge:\t{response.RequestCharge:0.00}");
}

{
// <query-items>
// <query_items>
var query = new QueryDefinition(
query: "SELECT * FROM products p WHERE p.category = @category"
)
Expand All @@ -118,11 +120,12 @@
FeedResponse<Product> response = await feed.ReadNextAsync();
foreach (Product item in response)
{
// Do something with each item
await WriteToConsoleAync($"Found item:\t{item.name}\t[{item.id}]");
}
await WriteToConsoleAync($"Request charge:\t{response.RequestCharge:0.00}");
}
// </query-items>
// </query_items>
}

await WriteToConsoleAync("Current Status:\tStopping...");
Expand Down
11 changes: 7 additions & 4 deletions src/web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
builder.Services.AddServerSideBlazor();

builder.Services.AddSingleton<CosmosClient>((_) =>
// <create-client>
new CosmosClient(
{
// <create_client>
CosmosClient client = new(
accountEndpoint: builder.Configuration["AZURE_COSMOS_DB_NOSQL_ENDPOINT"]!,
tokenCredential: new DefaultAzureCredential()
// </create-client>
));
);
// </create_client>
return client;
});

var app = builder.Build();

Expand Down

0 comments on commit c0524ae

Please sign in to comment.