-
Notifications
You must be signed in to change notification settings - Fork 2
/
CollectionsUsage.cs
78 lines (69 loc) · 2.95 KB
/
CollectionsUsage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Text;
using QueryCat.Backend;
using QueryCat.Backend.Core.Data;
using QueryCat.Backend.Core.Fetch;
using QueryCat.Backend.Core.Types;
using QueryCat.Backend.Formatters;
using QueryCat.Backend.Storage;
namespace QueryCat.Samples.Collection;
internal class CollectionsUsage : BaseUsage
{
private class Building(string name, string postalCode)
{
public string Name { get; } = name;
public string PostalCode { get; } = postalCode;
}
private class City(string postalCode, string city)
{
public string PostalCode { get; } = postalCode;
public string CityName { get; } = city;
}
/// <inheritdoc />
public override void Run()
{
// Arrange.
var executionThread = new ExecutionThreadBootstrapper().Create();
var buildings = new List<Building>
{
new("Hotel Indigo San Diego-Gaslamp Quarter, an IHG Hotel", "92101"),
new("San Diego Chinese Historical Museum Chuang Archive and Learning Center", "92101"),
new("Aristocrat Gallery", "92101"),
new("Gus's World Famous Fried Chicken", "92701"),
new("Music Center Garage", "90012"),
new("Homeboy Industries", "90012"),
new("Saritasa - Custom Software Development Company", "20411"),
new("Bloomberg", "10022"),
};
var cities = new List<City>
{
new("92101", "San Diego, CA"),
new("92701", "Santa Ana, CA"),
new("90012", "Los Angeles, CA"),
new("20411", "Newport Beach, CA"),
};
var buildingsInput = new EnumerableRowsInput<Building>(buildings,
builder => builder
.AddProperty("name", f => f.Name)
.AddProperty("zip", f => f.PostalCode));
var citiesInput = new EnumerableRowsInput<City>(cities,
builder => builder
.AddProperty("zip", f => f.PostalCode)
.AddProperty("city", f => f.CityName));
// Act.
executionThread.TopScope.Variables["buildings"] = VariantValue.CreateFromObject(buildingsInput);
executionThread.TopScope.Variables["cities"] = VariantValue.CreateFromObject(citiesInput);
var result = executionThread.Run(
"SELECT b.name, c.city FROM buildings b LEFT JOIN cities c ON b.zip = c.zip;");
// Out.
var sb = new StringBuilder();
new TextTableOutput(sb).Write(result.As<IRowsIterator>(), adjustColumnsLengths: true);
Console.WriteLine(sb);
/*
| b.name | c.city |
| ---------------------------------------------------------------------- | ----------------- |
| Hotel Indigo San Diego-Gaslamp Quarter, an IHG Hotel | San Diego, CA |
| San Diego Chinese Historical Museum Chuang Archive and Learning Center | San Diego, CA |
...
*/
}
}