-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from mk3008/419-experiment-typesafe-query-bui…
…lder-cte 419 experiment typesafe query builder cte
- Loading branch information
Showing
25 changed files
with
1,007 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Carbunql.Analysis.Parser; | ||
using Carbunql.Building; | ||
|
||
namespace Carbunql.TypeSafe; | ||
|
||
public class CTEDataSet(string name, SelectQuery query) : IDataSet | ||
{ | ||
public string Name { get; set; } = name; | ||
|
||
public Materialized Materialized { get; set; } = Materialized.Undefined; | ||
|
||
public SelectQuery Query { get; init; } = query; | ||
|
||
public List<string> Columns { get; init; } = query.GetColumnNames().ToList(); | ||
|
||
public SelectQuery BuildFromClause(SelectQuery query, string alias) | ||
{ | ||
var cte = query.With(Query).As(Name); | ||
cte.Materialized = Materialized; | ||
query.From(new CTETable(cte).ToSelectable()).As(alias); | ||
return query; | ||
} | ||
|
||
public SelectQuery BuildJoinClause(SelectQuery query, string join, string alias, string condition) | ||
{ | ||
var cte = query.With(Query).As(Name); | ||
cte.Materialized = Materialized; | ||
|
||
var r = query.FromClause!.Join(cte, join).As(alias); | ||
if (!string.IsNullOrEmpty(condition)) | ||
{ | ||
r.On(_ => ValueParser.Parse(condition)); | ||
} | ||
return query; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Carbunql.TypeSafe; | ||
|
||
public struct CTEDefinition | ||
{ | ||
public string Name { get; set; } | ||
|
||
public Type RowType { get; set; } | ||
|
||
public string Query { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Carbunql.Clauses; | ||
using Carbunql.Tables; | ||
|
||
namespace Carbunql.TypeSafe; | ||
|
||
public class CTETable(CommonTable ct) : TableBase | ||
{ | ||
public CommonTable CommonTable { get; init; } = ct; | ||
|
||
/// <inheritdoc/> | ||
public override IEnumerable<Token> GetTokens(Token? parent) | ||
{ | ||
yield return new Token(this, parent, CommonTable.Alias); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override IEnumerable<QueryParameter> GetParameters() | ||
{ | ||
yield break; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override IList<string> GetColumnNames() => CommonTable.GetColumnNames().ToList(); | ||
|
||
/// <inheritdoc/> | ||
public override IEnumerable<PhysicalTable> GetPhysicalTables() | ||
{ | ||
yield break; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override IEnumerable<CommonTable> GetCommonTables() | ||
{ | ||
yield break; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override IEnumerable<SelectQuery> GetInternalQueries() | ||
{ | ||
yield break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Carbunql.Annotations; | ||
|
||
namespace Carbunql.TypeSafe; | ||
|
||
public interface IDataRow | ||
{ | ||
[IgnoreMapping] | ||
IDataSet DataSet { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Carbunql.TypeSafe; | ||
|
||
public interface IDataSet | ||
{ | ||
public List<string> Columns { get; } | ||
|
||
SelectQuery BuildFromClause(SelectQuery query, string alias); | ||
|
||
SelectQuery BuildJoinClause(SelectQuery query, string join, string alias, string condition = ""); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Carbunql.Analysis.Parser; | ||
using Carbunql.Building; | ||
using Carbunql.Clauses; | ||
using Carbunql.Definitions; | ||
using Carbunql.Tables; | ||
|
||
namespace Carbunql.TypeSafe; | ||
|
||
public class PhysicalTableDataSet(ITable tb, IEnumerable<string> columns) : IDataSet | ||
{ | ||
public SelectableTable Table { get; set; } = new PhysicalTable(tb).ToSelectable(); | ||
|
||
public List<string> Columns { get; init; } = columns.ToList(); | ||
|
||
public SelectQuery BuildFromClause(SelectQuery query, string alias) | ||
{ | ||
query.From(Table).As(alias); | ||
return query; | ||
} | ||
|
||
public SelectQuery BuildJoinClause(SelectQuery query, string join, string alias, string condition) | ||
{ | ||
var r = query.FromClause!.Join(Table, join).As(alias); | ||
if (!string.IsNullOrEmpty(condition)) | ||
{ | ||
r.On(_ => ValueParser.Parse(condition)); | ||
} | ||
return query; | ||
} | ||
} |
Oops, something went wrong.