Skip to content

Commit

Permalink
Implement grouping of where clause via Clusters (#17)
Browse files Browse the repository at this point in the history
* minor renames

* code cleanup

* Implementation of grouped where clauses

* Fix testing app

* Update NuGet version

* upgrade dotnet cli
  • Loading branch information
kuromukira authored Mar 31, 2023
1 parent e6661f2 commit ac14475
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 155 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dotnet-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
dotnet-version: '7.x'
include-prerelease: true
- name: Restore
working-directory: ./code/
Expand All @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
dotnet-version: '7.x'
include-prerelease: true
- name: Build
working-directory: ./code/
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Version>1.4.0</Version>
<Version>2.0.0</Version>
2 changes: 1 addition & 1 deletion code/DarkMatter/DarkMatter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
Expand Down
17 changes: 12 additions & 5 deletions code/DarkMatter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@
// actual use of UniverseQuery
(Gravity g, IList<MyObject> T) = await galaxy.Paged(
page: new Q.Page(50),
catalysts: new List<Catalyst>
clusters: new List<Cluster>()
{
new(nameof(MyObject.Links), "<VALUE TO QUERY>", Operator: Q.Operator.In),
new(nameof(MyObject.Code), "<VALUE TO QUERY>", Where: Q.Where.Or)
new(Catalysts: new List<Catalyst>
{
new(nameof(MyObject.Links), "<VALUE TO QUERY>", Operator: Q.Operator.In),
new(nameof(MyObject.Code), "<VALUE TO QUERY>", Where: Q.Where.Or)
}, Where: Q.Where.And),
new(Catalysts: new List<Catalyst>
{
new(nameof(MyObject.Name), Operator: Q.Operator.Defined),
new(nameof(MyObject.Description), Operator: Q.Operator.Defined)
}, Where: Q.Where.And)
},
columnOptions: new(
Names: new List<string>
Expand Down Expand Up @@ -67,8 +75,7 @@ class MyObject : ICosmicEntity
public DateTime AddedOn { get; set; }
public DateTime? ModifiedOn { get; set; }

[JsonIgnore]
public string PartitionKey => Code;
[JsonIgnore] public string PartitionKey => Code;

public string Code { get; set; }

Expand Down
205 changes: 96 additions & 109 deletions code/Universe/Galaxy.cs

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions code/Universe/Interfaces/IGalaxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,15 @@ public interface IGalaxy<T> where T : ICosmicEntity
/// <summary>
/// Get one model from the database
/// </summary>
Task<(Gravity g, T T)> Get(Catalyst catalyst, IList<string> columns = null);
Task<(Gravity g, T T)> Get(IList<Cluster> clusters, IList<string> columns = null);

/// <summary>
/// Get one model from the database
/// </summary>
Task<(Gravity g, T T)> Get(IList<Catalyst> catalysts, IList<string> columns = null);

/// <summary>
/// Get a paginated list from the database
/// </summary>
Task<(Gravity g, IList<T> T)> List(Catalyst catalyst, ColumnOptions? columnOptions = null, IList<Sorting.Option> sorting = null, IList<string> group = null);

/// <summary>
/// Get a paginated list from the database
/// Get list from the database
/// </summary>
Task<(Gravity g, IList<T> T)> List(IList<Catalyst> catalysts, ColumnOptions? columnOptions = null, IList<Sorting.Option> sorting = null, IList<string> group = null);
Task<(Gravity g, IList<T> T)> List(IList<Cluster> clusters, ColumnOptions? columnOptions = null, IList<Sorting.Option> sorting = null, IList<string> group = null);

/// <summary>
/// Get a paginated list from the database
/// </summary>
Task<(Gravity g, IList<T> T)> Paged(Q.Page page, IList<Catalyst> catalysts, ColumnOptions? columnOptions = null, IList<Sorting.Option> sorting = null, IList<string> group = null);
Task<(Gravity g, IList<T> T)> Paged(Q.Page page, IList<Cluster> clusters, ColumnOptions? columnOptions = null, IList<Sorting.Option> sorting = null, IList<string> group = null);
}
2 changes: 1 addition & 1 deletion code/Universe/Options/SortingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum Direction
}

/// <summary></summary>
public record Option(string Column, Direction Direction = Direction.ASC);
public readonly record struct Option(string Column, Direction Direction = Direction.ASC);
}

/// <summary></summary>
Expand Down
8 changes: 8 additions & 0 deletions code/Universe/Options/WhereClause.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Universe.Options.Query;

/// <summary>
/// Clusters are group of Catalysts that are joined by a Where operator (eg AND / OR). This will divide the where clause into multiple groups.
/// </summary>
/// <param name="Catalysts">Catalysts under one group / cluster</param>
/// <param name="Where">Where operator (eg AND / OR)</param>
public readonly record struct Cluster(IList<Catalyst> Catalysts, Q.Where Where = Q.Where.And);
16 changes: 8 additions & 8 deletions code/Universe/UniverseQuery.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<LangVersion>10.0</LangVersion>
<LangVersion>11.0</LangVersion>
<Description>A simpler way of querying a CosmosDb Namespace</Description>
<Copyright>Nor Gelera 2022</Copyright>
<Owners>Nor Gelera</Owners>
Expand All @@ -15,16 +15,16 @@
<PropertyGroup>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>A simpler way of querying a CosmosDb Namespace</Description>
<Copyright>Nor Gelera 2022</Copyright>
<Copyright>Nor Gelera 2023</Copyright>
<RepositoryUrl>https://github.com/kuromukira/universe</RepositoryUrl>
<PackageTags>cosmos simple query</PackageTags>
<RepositoryType>Git</RepositoryType>
<Authors>Nor Gelera</Authors>
<Product>Universe</Product>
<Version>1.4.1</Version>
<Version>2.0.0</Version>
<PackageReleaseNotes>View release on https://github.com/kuromukira/universe/releases</PackageReleaseNotes>
<AssemblyVersion>1.4.1.0</AssemblyVersion>
<FileVersion>1.4.1.0</FileVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand All @@ -37,8 +37,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.31.0" />
<PackageReference Include="System.Text.Json" Version="6.0.6" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.32.3" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
38 changes: 24 additions & 14 deletions code/Universe/UniverseQuery.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac14475

Please sign in to comment.