Skip to content

Commit

Permalink
Merge pull request #11 from markjbrown/attribute-array
Browse files Browse the repository at this point in the history
Sample update
  • Loading branch information
markjbrown authored Sep 10, 2023
2 parents 7646c42 + 4a53c36 commit 871f2b8
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 956 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/attribute-array/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"workspaceFolder": "/workspace/attribute-array/source/",
"postAttachCommand": "dotnet build Cosmos_Patterns_Attribute.sln",
"postAttachCommand": "dotnet build AttributeArray.csproj",
"customizations": {
"codespaces": {
"openFiles": [
Expand Down
343 changes: 73 additions & 270 deletions attribute-array/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>DataUploader</RootNamespace>
<RootNamespace>AttributeArray</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Content Include="appsettings.*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<None Remove="appsettings.Development.json" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
Expand All @@ -20,7 +21,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.35.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
Expand Down
22 changes: 0 additions & 22 deletions attribute-array/source/Cosmos_Patterns_Attribute.sln

This file was deleted.

12 changes: 0 additions & 12 deletions attribute-array/source/Models/Hotel.cs

This file was deleted.

38 changes: 24 additions & 14 deletions attribute-array/source/Models/Product.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
namespace DataUploader.Models;
namespace AttributeArray.Models;

internal sealed record Product();

internal sealed record AttributePropertyProduct(
string Id,
string ProductId,
string Name,
string Category,
decimal Price,
string Price,
int SizeSmall,
int SizeMedium,
int SizeLarge
)
{
public string EntityType { get; init; } = nameof(Product);
}
int SizeLarge,
string EntityType
);


internal sealed record AttributeArrayProduct(
string Id,
string ProductId,
string Name,
string Category,
decimal Price,
IList<ProductSize> Sizes
)
{
public string EntityType { get; init; } = nameof(Product);
}
string Price,
IList<ProductSize> Sizes,
string EntityType
);


internal sealed record ProductSize(
string Size,
int Count
);

internal sealed record PropertyQueryResult(
string Name,
int SizeSmall,
int SizeMedium,
int SizeLarge
);

internal sealed record ArrayQueryResult(
string Name,
string Size,
int Count
);
41 changes: 0 additions & 41 deletions attribute-array/source/Models/Room.cs

This file was deleted.

2 changes: 1 addition & 1 deletion attribute-array/source/Options/Cosmos.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DataUploader.Options;
namespace AttributeArray.Options;

public class Cosmos
{
Expand Down
29 changes: 7 additions & 22 deletions attribute-array/source/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DataUploader.Options;
using DataUploader.Services;
using AttributeArray.Options;
using AttributeArray.Services;
using Microsoft.Azure.Cosmos;
using Microsoft.Extensions.Configuration;
using Spectre.Console;
Expand Down Expand Up @@ -38,49 +38,34 @@

Database database = await client.CreateDatabaseIfNotExistsAsync(
id: "CosmosPatterns",
throughput: 400
throughputProperties: ThroughputProperties.CreateAutoscaleThroughput(1000)
);

Console.Write(
new Panel("[green]Attribute upload utility featuring sample queries[/]")
new Panel("[green]Sample comparing Attribute Array Pattern to Property-based Attributes[/]")
.BorderColor(Color.White)
.RoundedBorder()
.Expand()
);

Console.Write(
new Rule("[yellow]Property and array-based product attributes[/]")
new Rule("[yellow]Property and Array-based product attributes[/]")
.LeftJustified()
.RuleStyle("olive")
);

Container productsContainer = await database.CreateContainerIfNotExistsAsync(
id: "Products",
id: "ArrayAttributes",
partitionKeyPath: "/productId"
);

// Use product container as an example
await new ProductService(productsContainer)
.GenerateProductsAsync();

Console.Write(
new Rule("[yellow]Attribute and Non-attribute based hotel rooms[/]")
.LeftJustified()
.RuleStyle("olive")
);

Container hotelRoomsContainer = await database.CreateContainerIfNotExistsAsync(
id: "Hotels",
partitionKeyPath: "/hotelId"
);

// Use hotel room price container as an example
await new HotelService(hotelRoomsContainer)
.GenerateHotelRoomsAsync();

Console.Write(
new Panel("[green]The attribute upload utlity has finished. Use the Data Explorer in Azure Cosmos DB to run additional queries.[/]")
.BorderColor(Color.White)
.RoundedBorder()
.Expand()
);
);
Loading

0 comments on commit 871f2b8

Please sign in to comment.