Skip to content

Commit f085255

Browse files
_
1 parent 79b2305 commit f085255

File tree

3 files changed

+93
-90
lines changed

3 files changed

+93
-90
lines changed

Persistence.sln

-31
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30011.22
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper", "Dapper\Dapper.csproj", "{0A5018AD-1E0B-40EA-9D3E-96809D781A8C}"
7-
EndProject
86
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{64573428-E41D-4B03-9A9E-D6DBFB00F19C}"
97
ProjectSection(SolutionItems) = preProject
108
.github\workflows\build.yaml = .github\workflows\build.yaml
@@ -14,20 +12,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Specs", "Specs", "{8DC30A4E
1412
EndProject
1513
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Query", "Query\Query.csproj", "{31ADD95B-CED7-427B-8C23-DFA8531EF1D0}"
1614
EndProject
17-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Query.Dapper", "Query.Dapper\Query.Dapper.csproj", "{EA4F6C90-5B03-427B-B82C-C547C4D440C5}"
18-
EndProject
1915
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain", "Domain\Domain.csproj", "{BF3A0667-B8B7-4A07-ABCB-16DB5C1F3ED7}"
2016
EndProject
21-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain.Dapper", "Domain.Dapper\Domain.Dapper.csproj", "{B7E4FE80-5F09-4F8D-B9E4-17A9E6469659}"
22-
EndProject
2317
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cosmos", "Cosmos\Cosmos.csproj", "{0B70555F-BE6A-4E61-A22C-4C376C36ABE6}"
2418
EndProject
2519
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Domain.Cosmos", "Domain.Cosmos\Domain.Cosmos.csproj", "{30043D7D-D65B-4158-9A18-30FAE1345ACF}"
2620
EndProject
27-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapper", "Specs\Dapper\Dapper.csproj", "{DA733487-864C-446E-A2A3-405FFE68E172}"
28-
EndProject
29-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bdd.Dapper", "Bdd.Dapper\Bdd.Dapper.csproj", "{1C203015-5BB3-42CB-A912-0099586F3B13}"
30-
EndProject
3121
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Query.Cosmos", "Query.Cosmos\Query.Cosmos.csproj", "{CA45544E-E7C0-4F16-A9DA-16F980E00768}"
3222
EndProject
3323
Global
@@ -36,26 +26,14 @@ Global
3626
Release|Any CPU = Release|Any CPU
3727
EndGlobalSection
3828
GlobalSection(ProjectConfigurationPlatforms) = postSolution
39-
{0A5018AD-1E0B-40EA-9D3E-96809D781A8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40-
{0A5018AD-1E0B-40EA-9D3E-96809D781A8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
41-
{0A5018AD-1E0B-40EA-9D3E-96809D781A8C}.Release|Any CPU.ActiveCfg = Release|Any CPU
42-
{0A5018AD-1E0B-40EA-9D3E-96809D781A8C}.Release|Any CPU.Build.0 = Release|Any CPU
4329
{31ADD95B-CED7-427B-8C23-DFA8531EF1D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4430
{31ADD95B-CED7-427B-8C23-DFA8531EF1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
4531
{31ADD95B-CED7-427B-8C23-DFA8531EF1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
4632
{31ADD95B-CED7-427B-8C23-DFA8531EF1D0}.Release|Any CPU.Build.0 = Release|Any CPU
47-
{EA4F6C90-5B03-427B-B82C-C547C4D440C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48-
{EA4F6C90-5B03-427B-B82C-C547C4D440C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
49-
{EA4F6C90-5B03-427B-B82C-C547C4D440C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
50-
{EA4F6C90-5B03-427B-B82C-C547C4D440C5}.Release|Any CPU.Build.0 = Release|Any CPU
5133
{BF3A0667-B8B7-4A07-ABCB-16DB5C1F3ED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
5234
{BF3A0667-B8B7-4A07-ABCB-16DB5C1F3ED7}.Debug|Any CPU.Build.0 = Debug|Any CPU
5335
{BF3A0667-B8B7-4A07-ABCB-16DB5C1F3ED7}.Release|Any CPU.ActiveCfg = Release|Any CPU
5436
{BF3A0667-B8B7-4A07-ABCB-16DB5C1F3ED7}.Release|Any CPU.Build.0 = Release|Any CPU
55-
{B7E4FE80-5F09-4F8D-B9E4-17A9E6469659}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56-
{B7E4FE80-5F09-4F8D-B9E4-17A9E6469659}.Debug|Any CPU.Build.0 = Debug|Any CPU
57-
{B7E4FE80-5F09-4F8D-B9E4-17A9E6469659}.Release|Any CPU.ActiveCfg = Release|Any CPU
58-
{B7E4FE80-5F09-4F8D-B9E4-17A9E6469659}.Release|Any CPU.Build.0 = Release|Any CPU
5937
{0B70555F-BE6A-4E61-A22C-4C376C36ABE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
6038
{0B70555F-BE6A-4E61-A22C-4C376C36ABE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
6139
{0B70555F-BE6A-4E61-A22C-4C376C36ABE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -64,14 +42,6 @@ Global
6442
{30043D7D-D65B-4158-9A18-30FAE1345ACF}.Debug|Any CPU.Build.0 = Debug|Any CPU
6543
{30043D7D-D65B-4158-9A18-30FAE1345ACF}.Release|Any CPU.ActiveCfg = Release|Any CPU
6644
{30043D7D-D65B-4158-9A18-30FAE1345ACF}.Release|Any CPU.Build.0 = Release|Any CPU
67-
{DA733487-864C-446E-A2A3-405FFE68E172}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
68-
{DA733487-864C-446E-A2A3-405FFE68E172}.Debug|Any CPU.Build.0 = Debug|Any CPU
69-
{DA733487-864C-446E-A2A3-405FFE68E172}.Release|Any CPU.ActiveCfg = Release|Any CPU
70-
{DA733487-864C-446E-A2A3-405FFE68E172}.Release|Any CPU.Build.0 = Release|Any CPU
71-
{1C203015-5BB3-42CB-A912-0099586F3B13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
72-
{1C203015-5BB3-42CB-A912-0099586F3B13}.Debug|Any CPU.Build.0 = Debug|Any CPU
73-
{1C203015-5BB3-42CB-A912-0099586F3B13}.Release|Any CPU.ActiveCfg = Release|Any CPU
74-
{1C203015-5BB3-42CB-A912-0099586F3B13}.Release|Any CPU.Build.0 = Release|Any CPU
7545
{CA45544E-E7C0-4F16-A9DA-16F980E00768}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
7646
{CA45544E-E7C0-4F16-A9DA-16F980E00768}.Debug|Any CPU.Build.0 = Debug|Any CPU
7747
{CA45544E-E7C0-4F16-A9DA-16F980E00768}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -81,7 +51,6 @@ Global
8151
HideSolutionNode = FALSE
8252
EndGlobalSection
8353
GlobalSection(NestedProjects) = preSolution
84-
{DA733487-864C-446E-A2A3-405FFE68E172} = {8DC30A4E-9EE3-47E7-BDDE-2029DADC59F2}
8554
EndGlobalSection
8655
GlobalSection(ExtensibilityGlobals) = postSolution
8756
SolutionGuid = {766E5550-B7C1-42B9-8791-644B1B44300B}

Query.Cosmos/Query.cs

+83-54
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,111 @@
55
using static Sensemaking.Query.Cosmos.Querying;
66
using Database = Sensemaking.Cosmos.Database;
77

8-
namespace Sensemaking.Query.Cosmos
8+
namespace Sensemaking.Query.Cosmos;
9+
10+
public abstract class Query<T, U> : IQuery<T, U>
911
{
10-
public abstract class Query<T, U> : IQuery<T, U>
12+
public async Task<IEnumerable<U>> GetResultsAsync(T parameters)
1113
{
12-
public async Task<IEnumerable<U>> GetResultsAsync(T parameters)
13-
{
14-
var spec = GetQuerySpecification(parameters);
15-
var results = new List<U>();
16-
var iterator = Database.GetClient().GetDatabase(Database.DatabaseName!).GetContainer(spec.Container).GetItemQueryIterator<U>(new QueryDefinition(spec.Query));
14+
var spec = GetQuerySpecification(parameters);
15+
var results = new List<U>();
16+
var iterator = Database.GetClient().GetDatabase(Database.DatabaseName!).GetContainer(spec.Container).GetItemQueryIterator<U>(new QueryDefinition(spec.Query));
1717

18-
while(iterator.HasMoreResults)
19-
results.AddRange(await iterator.ReadNextAsync().ConfigureAwait(false));
18+
while (iterator.HasMoreResults)
19+
results.AddRange(await iterator.ReadNextAsync().ConfigureAwait(false));
2020

21-
return results;
22-
}
21+
return results;
22+
}
2323

24-
protected abstract QuerySpecification GetQuerySpecification(T parameters);
24+
protected abstract QuerySpecification GetQuerySpecification(T parameters);
2525

26-
protected class QuerySpecification
26+
protected class QuerySpecification
27+
{
28+
public QuerySpecification(string container, string query)
2729
{
28-
public QuerySpecification(string container, string query)
29-
{
30-
Container = container;
31-
Query = query;
32-
}
33-
34-
public string Container { get; }
35-
public string Query { get; }
30+
Container = container;
31+
Query = query;
3632
}
33+
34+
public string Container { get; }
35+
public string Query { get; }
3736
}
37+
}
3838

39-
internal static class Querying
39+
internal static class Querying
40+
{
41+
internal static async Task<IEnumerable<T>> GetResults<T>((string Container, string Query) specification)
4042
{
41-
internal static async Task<IEnumerable<T>> GetResults<T>((string Container, string Query) specification)
42-
{
43-
var results = new List<T>();
44-
var iterator = Database.GetClient().GetDatabase(Database.DatabaseName!)
45-
.GetContainer(specification.Container)
46-
.GetItemQueryIterator<T>(new QueryDefinition(specification.Query));
43+
var results = new List<T>();
44+
var iterator = Database.GetClient().GetDatabase(Database.DatabaseName!)
45+
.GetContainer(specification.Container)
46+
.GetItemQueryIterator<T>(new QueryDefinition(specification.Query));
4747

48-
while(iterator.HasMoreResults)
49-
results.AddRange(await iterator.ReadNextAsync().ConfigureAwait(false));
48+
while (iterator.HasMoreResults)
49+
results.AddRange(await iterator.ReadNextAsync().ConfigureAwait(false));
5050

51-
return results;
52-
}
51+
return results;
5352
}
53+
}
5454

55-
public class Query<T>
55+
public class Query<T>
56+
{
57+
private readonly (string Container, string Query) specification;
58+
59+
public Query(string container, string query) : this(new(container, query))
5660
{
57-
private readonly (string Container, string Query) specification;
61+
}
5862

59-
public Query(string container, string query) : this(new(container, query)) { }
60-
public Query((string Container, string Query) specification)
61-
{
62-
this.specification = specification;
63-
}
63+
public Query((string Container, string Query) specification)
64+
{
65+
this.specification = specification;
66+
}
6467

65-
public async Task<IEnumerable<T>> GetResults()
66-
{
67-
return await GetResults<T>(specification);
68-
}
68+
public async Task<IEnumerable<T>> GetResults()
69+
{
70+
return await GetResults<T>(specification);
6971
}
72+
}
73+
74+
public class ParameterisedQuery<T, U>
75+
{
76+
private readonly (string Container, Func<T, string> BuildQuery) specification;
7077

71-
public class ParameterisedQuery<T, U>
78+
public ParameterisedQuery(string container, Func<T, string> buildQuery) : this(new(container, buildQuery))
7279
{
73-
private readonly (string Container, Func<T, string> BuildQuery) specification;
80+
}
7481

75-
public ParameterisedQuery(string container, Func<T, string> buildQuery) : this(new(container, buildQuery)) { }
76-
public ParameterisedQuery((string Container, Func<T, string> BuildQuery) specification)
77-
{
78-
this.specification = specification;
79-
}
82+
public ParameterisedQuery((string Container, Func<T, string> BuildQuery) specification)
83+
{
84+
this.specification = specification;
85+
}
8086

81-
public async Task<IEnumerable<U>> GetResults(T parameters)
82-
{
83-
return await GetResults<U>((specification.Container, specification.BuildQuery(parameters)));
84-
}
87+
public async Task<IEnumerable<U>> GetResults(T parameters)
88+
{
89+
return await GetResults<U>((specification.Container, specification.BuildQuery(parameters)));
8590
}
8691
}
92+
93+
public interface IRunQueries
94+
{
95+
Task<IEnumerable<T>> GetResults<T>(string container, string query);
96+
Task<IEnumerable<T>> GetResults<T>((string Container, string Query) definition);
97+
}
98+
99+
public class QueryRunner : IRunQueries
100+
{
101+
public Task<IEnumerable<T>> GetResults<T>(string container, string query) => GetResults<T>((container, query));
102+
103+
public async Task<IEnumerable<T>> GetResults<T>((string Container, string Query) definition)
104+
{
105+
var results = new List<T>();
106+
var iterator = Database.GetClient().GetDatabase(Database.DatabaseName!)
107+
.GetContainer(definition.Container)
108+
.GetItemQueryIterator<T>(new QueryDefinition(definition.Query));
109+
110+
while (iterator.HasMoreResults)
111+
results.AddRange(await iterator.ReadNextAsync().ConfigureAwait(false));
112+
113+
return results;
114+
}
115+
}

Query/IQuery.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
using System.Collections.Generic;
22
using System.Threading.Tasks;
33

4-
namespace Sensemaking.Query
4+
namespace Sensemaking.Query;
5+
6+
public interface IQuery<in T, U>
7+
{
8+
Task<IEnumerable<U>> GetResultsAsync(T parameters);
9+
}
10+
11+
public interface IRunQueries
512
{
6-
public interface IQuery<in T, U>
7-
{
8-
Task<IEnumerable<U>> GetResultsAsync(T parameters);
9-
}
13+
Task<IEnumerable<T>> GetResults<T>(string container, string query);
14+
Task<IEnumerable<T>> GetResults<T>((string Container, string Query) definition);
1015
}

0 commit comments

Comments
 (0)