Skip to content

Commit

Permalink
Parse FROM, UNION and UNION ALL
Browse files Browse the repository at this point in the history
  • Loading branch information
weelink committed Jul 19, 2019
1 parent 33f6af8 commit 0004bdc
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/FluentSQL.Tests/Api/ApiDesign.cs
Expand Up @@ -118,7 +118,7 @@ public async Task TestApi()
*
* UNION
*
* SELECT "other_dummy", id
* SELECT "other_dummy" AS CustomerName, id
* FROM dbo.customers
*/
Query<ExampleParameters, UnionResult> unionQuery =
Expand All @@ -129,28 +129,25 @@ public async Task TestApi()
.Select(() => c.Name).As(result => result.CustomerName)
.Select(() => l.Price.Sum()).As(result => result.TotalAmount)
.Where(p => c.Id > p.Limit)
.UnionAll(
model.Query<UnionResult>()
.From(() => c)
.Select(() => c.Name).As(result => result.CustomerName)
.Select(() => 1).As(result => result.TotalAmount)
.Union(
model.Query<UnionResult>()
.WithParameters<ExampleParameters>()
.From(() => model.Customers)
.Select(() => "dummy")
.Select(() => 1)
.Union(
model.Query<UnionResult>()
.From(() => model.Customers)
.Select(() => "other_dummy")
.Select(() => model.Customers.Id))))
.UnionAll(model.Query<UnionResult>()
.From(() => c)
.Select(() => c.Name).As(result => result.CustomerName)
.Select(() => 1).As(result => result.TotalAmount)
)
.Union(model.Query<UnionResult>()
.WithParameters<ExampleParameters>()
.From(() => model.Customers)
.Select(() => "dummy")
.Select(() => 1)
)
.Union(model.Query<UnionResult>()
.From(() => model.Customers)
.Select(() => "other_dummy").As(result => result.CustomerName)
.Select(() => model.Customers.Id)
)
.Compile();

UnionResult unionResult = await SomeConnection.ExecuteAsync(unionQuery, p =>
{
p.Limit = 122;
});
UnionResult unionResult = await SomeConnection.ExecuteAsync(unionQuery, p => p.Limit = 122);
}
}
}
8 changes: 8 additions & 0 deletions src/FluentSQL.Tests/Api/ExampleParameters.cs
@@ -0,0 +1,8 @@
namespace FluentSQL.Tests.Api
{
public class ExampleParameters
{
public int Limit { get; set; }
public string InvoiceNumber { get; set; }
}
}
7 changes: 7 additions & 0 deletions src/FluentSQL.Tests/Api/SubqueryResult.cs
@@ -0,0 +1,7 @@
namespace FluentSQL.Tests.Api
{
public class SubqueryResult
{
public int InvoiceIdFromSubquery { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/FluentSQL.Tests/Api/UnionResult.cs
@@ -0,0 +1,8 @@
namespace FluentSQL.Tests.Api
{
public class UnionResult
{
public string CustomerName { get; set; }
public int TotalAmount { get; set; }
}
}
12 changes: 12 additions & 0 deletions src/FluentSQL/Compilation/Parser/FromNode.cs
@@ -0,0 +1,12 @@
namespace FluentSQL.Compilation.Parser
{
public class FromNode : AstNode
{
public FromNode(string @alias)
{
Alias = alias;
}

public string Alias { get; }
}
}
14 changes: 14 additions & 0 deletions src/FluentSQL/Compilation/Parser/UnionAllNode.cs
@@ -0,0 +1,14 @@
namespace FluentSQL.Compilation.Parser
{
public class UnionAllNode : AstNode
{
public UnionAllNode(AstNode first, AstNode second)
{
First = first;
Second = second;
}

public AstNode First { get; }
public AstNode Second { get; }
}
}
14 changes: 14 additions & 0 deletions src/FluentSQL/Compilation/Parser/UnionNode.cs
@@ -0,0 +1,14 @@
namespace FluentSQL.Compilation.Parser
{
public class UnionNode : AstNode
{
public UnionNode(AstNode first, AstNode second)
{
First = first;
Second = second;
}

public AstNode First { get; }
public AstNode Second { get; }
}
}

0 comments on commit 0004bdc

Please sign in to comment.