From 7fb59f42db757ec15f6db23b44518955dcf36fcc Mon Sep 17 00:00:00 2001 From: mk3008 Date: Tue, 27 Aug 2024 21:13:04 +0900 Subject: [PATCH] Enhancement: Added build method to SelectQuery class. The parsing process in the constructor may be abolished in the future, but since the impact is large, we will wait and see for a while. --- README.md | 12 +- demo/CarbunqlWeb/Pages/CTEQuery.razor | 4 +- demo/CarbunqlWeb/Pages/ColumnNameList.razor | 4 +- demo/CarbunqlWeb/Pages/Count.razor | 4 +- demo/CarbunqlWeb/Pages/CreateTable.razor | 4 +- demo/CarbunqlWeb/Pages/Delete.razor | 2 +- demo/CarbunqlWeb/Pages/Insert.razor | 2 +- .../CarbunqlWeb/Pages/InternalQueryList.razor | 4 +- demo/CarbunqlWeb/Pages/Merge.razor | 4 +- .../CarbunqlWeb/Pages/PhysicalTableList.razor | 4 +- .../Pages/QuerySource/EnsureAny.razor | 4 +- .../Pages/QuerySource/FilterColumn.razor | 4 +- .../Pages/QuerySource/FilterTable.razor | 4 +- .../Pages/QuerySource/Labels.razor | 4 +- .../Pages/SelectableItemList.razor | 4 +- .../Pages/SelectableTableList.razor | 4 +- demo/CarbunqlWeb/Pages/SubQuery.razor | 4 +- demo/CarbunqlWeb/Pages/TokenList.razor | 4 +- demo/CarbunqlWeb/Pages/Update.razor | 4 +- demo/DynamicColumn/Program.cs | 2 +- demo/DynamicFiltering/Program.cs | 2 +- demo/Filtering/Program.cs | 2 +- demo/Parse/Program.cs | 2 +- demo/QuerySource/Program.cs | 2 +- .../Extensions/ConstantExpressionExtension.cs | 4 +- .../Extensions/ExpresionExtension.cs | 4 +- .../Extensions/MemberExpressionExtension.cs | 4 +- .../Extensions/NewExpressionExtension.cs | 4 +- .../ParameterExpressionExtension.cs | 4 +- .../Extensions/UnaryExpressionExtension.cs | 4 +- .../FluentSelectQueryBuilder.cs | 4 +- src/Carbunql/Building/SelectQueryExtension.cs | 2 +- .../Fluent/SelectQueryWithExtensions.cs | 22 +-- src/Carbunql/IEnumerableExtension.cs | 142 +++++++++--------- src/Carbunql/MergeQuery.cs | 2 +- src/Carbunql/SelectQuery.cs | 23 ++- test/Carbunql.Analysis.Test/Demo.cs | 2 +- .../EscapedIdentiferTest.cs | 10 +- .../SelectQueryParserTest.cs | 8 +- .../StackOverFlowTest.cs | 2 +- test/Carbunql.Benchmark/Program.cs | 2 +- test/Carbunql.Building.Test/CopyTest.cs | 8 +- .../DemoBuildDiffQUery.cs | 4 +- test/Carbunql.Building.Test/FormatTest.cs | 6 +- .../GetInternalQueriesTest.cs | 14 +- .../QueryCommandMonitor.cs | 3 +- .../QuerySourceFilterTest.cs | 42 +++--- .../Carbunql.Building.Test/QuerySourceTest.cs | 46 +++--- test/Carbunql.Building.Test/SelectItemTest.cs | 8 +- .../SerializeTest.Clause.cs | 4 +- .../SerializeTest.Query.cs | 16 +- .../SerializeTest.TableBase.cs | 2 +- .../SerializeTest.ValueBase.cs | 2 +- test/Carbunql.Building.Test/ToCTETest.cs | 2 +- test/Carbunql.Building.Test/ToTextTest.cs | 8 +- test/Carbunql.Dapper.Test/DapperTest.cs | 4 +- test/Carbunql.DynamicQuery.Test/UnitTest1.cs | 16 +- .../Linq/CommonTableInfoParserTest.cs | 2 +- .../Linq/JoinTableInfoParserTest.cs | 4 +- .../Linq/TableInfoParserTest.cs | 2 +- test/Carbunql.Postgres.Test/SubQueryText.cs | 2 +- 61 files changed, 271 insertions(+), 257 deletions(-) diff --git a/README.md b/README.md index 07c63980..23395c4c 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ FROM var pname = ":category"; // Convert the selection query to an object - var sq = new SelectQuery(sql) + var sq = SelectQuery.Parse(sql) .GreaterThanOrEqualIfNotNullOrEmpty("price", minPrice) .LessThanOrEqualIfNotNullOrEmpty("price", maxPrice) .AddParameter(pname, category) @@ -277,7 +277,7 @@ Just pass the select query string to the constructor of the SelectQuery class. using Carbunql; var text = "select s.sale_id, s.store_id, date_trunc('month', s.sale_date) as allocate_ym, s.sale_price from sales as s"; -var sq = new SelectQuery(text); +var sq = SelectQuery.Parse(text); ``` ## Return the model to a select query @@ -292,7 +292,7 @@ The `ToOneLineText` method will output a single line without formatting. Use the using Carbunql; var text = "select s.sale_id, s.store_id, date_trunc('month', s.sale_date) as allocate_ym, s.sale_price from sales as s"; -var sq = new SelectQuery(text); +var sq = SelectQuery.Parse(text); var query = sq.ToOneLineText(); ``` @@ -328,7 +328,7 @@ where c1 = :val "; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); sq.AddParameter(":val", 1); using var r = cn.ExecuteReader(sq); @@ -391,7 +391,7 @@ The second argument is a delegate (or lambda expression) that takes the column s using Carbunql; var text = "select s.sale_id, s.store_id, date_trunc('month', s.sale_date) as allocate_ym, s.sale_price from sales as s"; -var sq = new SelectQuery(text) +var sq = SelectQuery.Parse(text) .AddWhere("sale_id", (source, column) => $"{source.Alias}.{column} = 1"); ``` @@ -402,7 +402,7 @@ using Carbunql; using Carbunql.Fluent; var text = "select s.sale_id, s.store_id, date_trunc('month', s.sale_date) as allocate_ym, s.sale_price from sales as s"; -var sq = new SelectQuery(text) +var sq = SelectQuery.Parse(text) .Equal("sale_id", 1); ``` diff --git a/demo/CarbunqlWeb/Pages/CTEQuery.razor b/demo/CarbunqlWeb/Pages/CTEQuery.razor index d75f2763..6a62c05a 100644 --- a/demo/CarbunqlWeb/Pages/CTEQuery.razor +++ b/demo/CarbunqlWeb/Pages/CTEQuery.razor @@ -40,7 +40,7 @@ using Carbunql; -var sql = new SelectQuery("select id, val from table_a as a") +var sql = SelectQuery.Parse("select id, val from table_a as a") .ToCteQuery(name, alias) .ToText(); @@ -116,7 +116,7 @@ ORDER BY } try { - fsql = new SelectQuery(sql) + fsql = SelectQuery.Parse(sql) .ToCTEQuery(name.Trim(), alias.Trim()) .ToText(); } diff --git a/demo/CarbunqlWeb/Pages/ColumnNameList.razor b/demo/CarbunqlWeb/Pages/ColumnNameList.razor index d5fabe63..48f38ba3 100644 --- a/demo/CarbunqlWeb/Pages/ColumnNameList.razor +++ b/demo/CarbunqlWeb/Pages/ColumnNameList.razor @@ -50,7 +50,7 @@ string sourcecode = @"using Carbunql; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); foreach (var item in sq.GetColumnNames()) { Console.WriteLine(item); @@ -82,7 +82,7 @@ from } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var sb = new StringBuilder(); fsql = string.Empty; diff --git a/demo/CarbunqlWeb/Pages/Count.razor b/demo/CarbunqlWeb/Pages/Count.razor index 4a28f5e5..9d7e2f81 100644 --- a/demo/CarbunqlWeb/Pages/Count.razor +++ b/demo/CarbunqlWeb/Pages/Count.razor @@ -51,7 +51,7 @@ string sourcecode = @"using Carbunql; using Carbunql.Building; -var sq = new SelectQuery(""select id, val from table_a as a""); +var sq = SelectQuery.Parse(""select id, val from table_a as a""); var q = sq.ToCountQuery(); Console.WriteLine(q.ToCommand().CommandText);"; @@ -77,7 +77,7 @@ Console.WriteLine(q.ToCommand().CommandText);"; } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); fsql = sq.ToCountQuery().ToCommand().CommandText; } catch (Exception ex) diff --git a/demo/CarbunqlWeb/Pages/CreateTable.razor b/demo/CarbunqlWeb/Pages/CreateTable.razor index 2388384d..bea39033 100644 --- a/demo/CarbunqlWeb/Pages/CreateTable.razor +++ b/demo/CarbunqlWeb/Pages/CreateTable.razor @@ -73,7 +73,7 @@ FROM string sourcecode = @"using Carbunql; using Carbunql.Building; -var sq = new SelectQuery(""select id, val from table_a as a""); +var sq = SelectQuery.Parse(""select id, val from table_a as a""); var q = sq.ToCreateTableQuery(""destinations"", isTemporary: true); Console.WriteLine(q.ToCommand().CommandText);"; @@ -101,7 +101,7 @@ Console.WriteLine(q.ToCommand().CommandText);"; } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var q = sq.ToCreateTableQuery(table, istemp); fsql = q.ToCommand().CommandText; } diff --git a/demo/CarbunqlWeb/Pages/Delete.razor b/demo/CarbunqlWeb/Pages/Delete.razor index 61d4d998..da3b2f1e 100644 --- a/demo/CarbunqlWeb/Pages/Delete.razor +++ b/demo/CarbunqlWeb/Pages/Delete.razor @@ -73,7 +73,7 @@ FROM string sourcecode = @"using Carbunql; using Carbunql.Building; -var sq = new SelectQuery(""select id, val from table_a as a""); +var sq = SelectQuery.Parse(""select id, val from table_a as a""); var q = sq.ToDeleteQuery(""destinations""); Console.WriteLine(q.ToCommand().CommandText);"; diff --git a/demo/CarbunqlWeb/Pages/Insert.razor b/demo/CarbunqlWeb/Pages/Insert.razor index fd30c7ed..adf8a805 100644 --- a/demo/CarbunqlWeb/Pages/Insert.razor +++ b/demo/CarbunqlWeb/Pages/Insert.razor @@ -71,7 +71,7 @@ FROM string sourcecode = @"using Carbunql; using Carbunql.Building; -var sq = new SelectQuery(""select id, val from table_a as a""); +var sq = SelectQuery.Parse(""select id, val from table_a as a""); var q = sq.ToInsertQuery(""destinations""); Console.WriteLine(q.ToCommand().CommandText);"; diff --git a/demo/CarbunqlWeb/Pages/InternalQueryList.razor b/demo/CarbunqlWeb/Pages/InternalQueryList.razor index 9c51a912..dcc61ea1 100644 --- a/demo/CarbunqlWeb/Pages/InternalQueryList.razor +++ b/demo/CarbunqlWeb/Pages/InternalQueryList.razor @@ -50,7 +50,7 @@ string sourcecode = @"using Carbunql; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); foreach (var item in sq.GetInternalQueries()) { Console.WriteLine(item.ToCommand().CommandText); @@ -149,7 +149,7 @@ order by } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var sb = new StringBuilder(); fsql = string.Empty; diff --git a/demo/CarbunqlWeb/Pages/Merge.razor b/demo/CarbunqlWeb/Pages/Merge.razor index 05217cbf..13ae8c81 100644 --- a/demo/CarbunqlWeb/Pages/Merge.razor +++ b/demo/CarbunqlWeb/Pages/Merge.razor @@ -62,7 +62,7 @@ using Carbunql.Building; string table = ""destinations""; string[] keys = new[] { ""id"", ""sub_id"" }; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); var mq = sq.ToMergeQuery(table, keys); mq.AddMatchedUpdate(); mq.AddNotMathcedInsertAsAutoNumber(); @@ -95,7 +95,7 @@ Console.WriteLine(mq.ToCommand().CommandText);"; try { var groupkeys = keys.Split(",").ToList().Select(x => x.Trim()).ToList(); - var sq =new SelectQuery(sql); + var sq =SelectQuery.Parse(sql); var mq = sq.ToMergeQuery(table, groupkeys); mq.AddMatchedUpdate(); mq.AddNotMathcedInsertAsAutoNumber(); diff --git a/demo/CarbunqlWeb/Pages/PhysicalTableList.razor b/demo/CarbunqlWeb/Pages/PhysicalTableList.razor index 08e846e9..23231d98 100644 --- a/demo/CarbunqlWeb/Pages/PhysicalTableList.razor +++ b/demo/CarbunqlWeb/Pages/PhysicalTableList.razor @@ -51,7 +51,7 @@ string sourcecode = @"using Carbunql; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); foreach (var item in sq.GetPhysicalTables()) { Console.WriteLine(item.ToText()); @@ -87,7 +87,7 @@ exists (select * from c where a.table_a_id = c.table_a_id)"; } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var sb = new StringBuilder(); fsql = string.Empty; diff --git a/demo/CarbunqlWeb/Pages/QuerySource/EnsureAny.razor b/demo/CarbunqlWeb/Pages/QuerySource/EnsureAny.razor index 3d3e3b09..b86e60ff 100644 --- a/demo/CarbunqlWeb/Pages/QuerySource/EnsureAny.razor +++ b/demo/CarbunqlWeb/Pages/QuerySource/EnsureAny.razor @@ -69,7 +69,7 @@ string sourcecode = @"using Carbunql; using Carbunql.Building; -var q = new SelectQuery(sql); +var q = SelectQuery.Parse(sql); q.GetQuerySources() .Where(x => x.ColumnNames.Contains(columnName)) .GetRootsBySource() @@ -101,7 +101,7 @@ Console.WriteLine(q.ToText());"; } try { - var q = new SelectQuery(sql); + var q = SelectQuery.Parse(sql); var sources = q.GetQuerySources().ToList(); q.GetQuerySources() diff --git a/demo/CarbunqlWeb/Pages/QuerySource/FilterColumn.razor b/demo/CarbunqlWeb/Pages/QuerySource/FilterColumn.razor index df76904e..ac94de37 100644 --- a/demo/CarbunqlWeb/Pages/QuerySource/FilterColumn.razor +++ b/demo/CarbunqlWeb/Pages/QuerySource/FilterColumn.razor @@ -69,7 +69,7 @@ string sourcecode = @"using Carbunql; using Carbunql.Building; -var q = new SelectQuery(sql); +var q = SelectQuery.Parse(sql); q.GetQuerySources() .Where(x => x.ColumnNames.Contains(columnName)) .GetRootsBySource() @@ -99,7 +99,7 @@ Console.WriteLine(q.ToText());"; } try { - var q = new SelectQuery(sql); + var q = SelectQuery.Parse(sql); var sources = q.GetQuerySources().ToList(); q.GetQuerySources() diff --git a/demo/CarbunqlWeb/Pages/QuerySource/FilterTable.razor b/demo/CarbunqlWeb/Pages/QuerySource/FilterTable.razor index ef9e78df..0f7cbc56 100644 --- a/demo/CarbunqlWeb/Pages/QuerySource/FilterTable.razor +++ b/demo/CarbunqlWeb/Pages/QuerySource/FilterTable.razor @@ -73,7 +73,7 @@ string sourcecode = @"using Carbunql; using Carbunql.Building; -var q = new SelectQuery(sql); +var q = SelectQuery.Parse(sql); q.GetQuerySources() .Where(x => x.GetTableFullName() == tableName && x.ColumnNames.Contains(columnName)) .GetRootsBySource() @@ -103,7 +103,7 @@ Console.WriteLine(q.ToText());"; } try { - var q = new SelectQuery(sql); + var q = SelectQuery.Parse(sql); var sources = q.GetQuerySources().ToList(); q.GetQuerySources() diff --git a/demo/CarbunqlWeb/Pages/QuerySource/Labels.razor b/demo/CarbunqlWeb/Pages/QuerySource/Labels.razor index 435a990d..12d07974 100644 --- a/demo/CarbunqlWeb/Pages/QuerySource/Labels.razor +++ b/demo/CarbunqlWeb/Pages/QuerySource/Labels.razor @@ -50,7 +50,7 @@ string sourcecode = @"using Carbunql; -var q = new SelectQuery(sql); +var q = SelectQuery.Parse(sql); var sources = q.GetQuerySources().ToList(); q.GetQuerySources().ForEach(x => @@ -80,7 +80,7 @@ Console.WriteLine(q.ToText());"; } try { - var q = new SelectQuery(sql); + var q = SelectQuery.Parse(sql); var sources = q.GetQuerySources().ToList(); q.GetQuerySources().ForEach(x => diff --git a/demo/CarbunqlWeb/Pages/SelectableItemList.razor b/demo/CarbunqlWeb/Pages/SelectableItemList.razor index d0784dc3..d0c8c55e 100644 --- a/demo/CarbunqlWeb/Pages/SelectableItemList.razor +++ b/demo/CarbunqlWeb/Pages/SelectableItemList.razor @@ -50,7 +50,7 @@ string sourcecode = @"using Carbunql; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); foreach (var item in sq.SelectClause!) { Console.WriteLine(item.ToCommand().CommandText); @@ -82,7 +82,7 @@ from } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var sb = new StringBuilder(); fsql = string.Empty; diff --git a/demo/CarbunqlWeb/Pages/SelectableTableList.razor b/demo/CarbunqlWeb/Pages/SelectableTableList.razor index b6a46b07..172f5267 100644 --- a/demo/CarbunqlWeb/Pages/SelectableTableList.razor +++ b/demo/CarbunqlWeb/Pages/SelectableTableList.razor @@ -50,7 +50,7 @@ string sourcecode = @"using Carbunql; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); foreach (var item in sq.GetSelectableTables()) { Console.WriteLine(item.ToCommand().CommandText); @@ -86,7 +86,7 @@ exists (select * from c where a.table_a_id = c.table_a_id)"; } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var sb = new StringBuilder(); fsql = string.Empty; diff --git a/demo/CarbunqlWeb/Pages/SubQuery.razor b/demo/CarbunqlWeb/Pages/SubQuery.razor index 0c92cb78..213c8242 100644 --- a/demo/CarbunqlWeb/Pages/SubQuery.razor +++ b/demo/CarbunqlWeb/Pages/SubQuery.razor @@ -37,7 +37,7 @@ using Carbunql; -var sql = new SelectQuery("select id, val from table_a as a") +var sql = SelectQuery.Parse("select id, val from table_a as a") .ToSubQuery(alias) .ToText(); @@ -109,7 +109,7 @@ ORDER BY } try { - fsql = new SelectQuery(sql) + fsql = SelectQuery.Parse(sql) .ToSubQuery(alias) .ToText(); } diff --git a/demo/CarbunqlWeb/Pages/TokenList.razor b/demo/CarbunqlWeb/Pages/TokenList.razor index dce91b4f..8434caaf 100644 --- a/demo/CarbunqlWeb/Pages/TokenList.razor +++ b/demo/CarbunqlWeb/Pages/TokenList.razor @@ -50,7 +50,7 @@ string sourcecode = @"using Carbunql; -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); foreach (var item in sq.GetTokens()) { Console.WriteLine(item.Text); @@ -82,7 +82,7 @@ from } try { - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var sb = new StringBuilder(); fsql = string.Empty; diff --git a/demo/CarbunqlWeb/Pages/Update.razor b/demo/CarbunqlWeb/Pages/Update.razor index 08f4ec31..3bc081fc 100644 --- a/demo/CarbunqlWeb/Pages/Update.razor +++ b/demo/CarbunqlWeb/Pages/Update.razor @@ -63,7 +63,7 @@ string sourcecode = @"using Carbunql; using Carbunql.Building; -var sq = new SelectQuery(""select id, val from table_a as a""); +var sq = SelectQuery.Parse(""select id, val from table_a as a""); var q = sq.ToUpdateQuery(""destination"", new[] { ""id"" }); Console.WriteLine(q.ToCommand().CommandText);"; @@ -92,7 +92,7 @@ Console.WriteLine(q.ToCommand().CommandText);"; try { var groupkeys = keys.Split(",").ToList().Select(x => x.Trim()).ToList(); - var sq =new SelectQuery(sql); + var sq =SelectQuery.Parse(sql); fsql = sq.ToUpdateQuery(table, groupkeys).ToCommand().CommandText; } catch (Exception ex) diff --git a/demo/DynamicColumn/Program.cs b/demo/DynamicColumn/Program.cs index 2cf99e48..8ccaffca 100644 --- a/demo/DynamicColumn/Program.cs +++ b/demo/DynamicColumn/Program.cs @@ -58,7 +58,7 @@ public static string GenerateCustomReportQuery(List columns) """; // Convert the query to an object - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); // Restrict the selected columns sq.FilterInColumns(columns); diff --git a/demo/DynamicFiltering/Program.cs b/demo/DynamicFiltering/Program.cs index 5aae7606..4699fc52 100644 --- a/demo/DynamicFiltering/Program.cs +++ b/demo/DynamicFiltering/Program.cs @@ -41,7 +41,7 @@ product as p var pname = ":category"; // Convert the selection query to an object - var sq = new SelectQuery(sql) + var sq = SelectQuery.Parse(sql) .GreaterThanOrEqualIfNotNullOrEmpty("price", minPrice) .LessThanOrEqualIfNotNullOrEmpty("price", maxPrice) .AddParameter(pname, category) diff --git a/demo/Filtering/Program.cs b/demo/Filtering/Program.cs index 70de8dc7..3b508d8a 100644 --- a/demo/Filtering/Program.cs +++ b/demo/Filtering/Program.cs @@ -1,6 +1,6 @@ using Carbunql; -using Carbunql.TypeSafe; using Carbunql.Building; +using Carbunql.TypeSafe; internal class Program { diff --git a/demo/Parse/Program.cs b/demo/Parse/Program.cs index a78e79b0..7e3de0d6 100644 --- a/demo/Parse/Program.cs +++ b/demo/Parse/Program.cs @@ -83,7 +83,7 @@ order by "; } -var sq = new SelectQuery(sql); +var sq = SelectQuery.Parse(sql); Console.WriteLine("\n> Format:"); Console.WriteLine(sq.ToText()); Console.WriteLine("\n> Model:"); diff --git a/demo/QuerySource/Program.cs b/demo/QuerySource/Program.cs index 14d4360c..338bbc26 100644 --- a/demo/QuerySource/Program.cs +++ b/demo/QuerySource/Program.cs @@ -14,7 +14,7 @@ sales as s var lower_limit = new DateTime(2024, 7, 20); -var query = new SelectQuery(sql) +var query = SelectQuery.Parse(sql) .OverrideSelect("journal_date", (source, item) => $"greatest({item}, {source.Query.AddParameter(":lower_limit", lower_limit)})") .AddNotExists(["sale_id"], "sale_journals") .AddWhere("request_timestamp", (source) => $"{source.Alias}.request_timestamp >= :lower_limit") diff --git a/src/Carbunql.TypeSafe/Extensions/ConstantExpressionExtension.cs b/src/Carbunql.TypeSafe/Extensions/ConstantExpressionExtension.cs index 70a78f99..f1e3e494 100644 --- a/src/Carbunql.TypeSafe/Extensions/ConstantExpressionExtension.cs +++ b/src/Carbunql.TypeSafe/Extensions/ConstantExpressionExtension.cs @@ -1,5 +1,5 @@ -using System.Linq.Expressions; -using Carbunql.TypeSafe.Building; +using Carbunql.TypeSafe.Building; +using System.Linq.Expressions; namespace Carbunql.TypeSafe.Extensions; diff --git a/src/Carbunql.TypeSafe/Extensions/ExpresionExtension.cs b/src/Carbunql.TypeSafe/Extensions/ExpresionExtension.cs index 041245fa..608b7240 100644 --- a/src/Carbunql.TypeSafe/Extensions/ExpresionExtension.cs +++ b/src/Carbunql.TypeSafe/Extensions/ExpresionExtension.cs @@ -1,5 +1,5 @@ -using System.Linq.Expressions; -using Carbunql.TypeSafe.Building; +using Carbunql.TypeSafe.Building; +using System.Linq.Expressions; namespace Carbunql.TypeSafe.Extensions; diff --git a/src/Carbunql.TypeSafe/Extensions/MemberExpressionExtension.cs b/src/Carbunql.TypeSafe/Extensions/MemberExpressionExtension.cs index 341eb455..13bb747c 100644 --- a/src/Carbunql.TypeSafe/Extensions/MemberExpressionExtension.cs +++ b/src/Carbunql.TypeSafe/Extensions/MemberExpressionExtension.cs @@ -1,5 +1,5 @@ -using System.Linq.Expressions; -using Carbunql.TypeSafe.Building; +using Carbunql.TypeSafe.Building; +using System.Linq.Expressions; namespace Carbunql.TypeSafe.Extensions; diff --git a/src/Carbunql.TypeSafe/Extensions/NewExpressionExtension.cs b/src/Carbunql.TypeSafe/Extensions/NewExpressionExtension.cs index 4a5d2341..2215dbaa 100644 --- a/src/Carbunql.TypeSafe/Extensions/NewExpressionExtension.cs +++ b/src/Carbunql.TypeSafe/Extensions/NewExpressionExtension.cs @@ -1,5 +1,5 @@ -using System.Linq.Expressions; -using Carbunql.TypeSafe.Building; +using Carbunql.TypeSafe.Building; +using System.Linq.Expressions; namespace Carbunql.TypeSafe.Extensions; diff --git a/src/Carbunql.TypeSafe/Extensions/ParameterExpressionExtension.cs b/src/Carbunql.TypeSafe/Extensions/ParameterExpressionExtension.cs index 431aea05..087722f7 100644 --- a/src/Carbunql.TypeSafe/Extensions/ParameterExpressionExtension.cs +++ b/src/Carbunql.TypeSafe/Extensions/ParameterExpressionExtension.cs @@ -1,5 +1,5 @@ -using System.Linq.Expressions; -using Carbunql.TypeSafe.Building; +using Carbunql.TypeSafe.Building; +using System.Linq.Expressions; namespace Carbunql.TypeSafe.Extensions; diff --git a/src/Carbunql.TypeSafe/Extensions/UnaryExpressionExtension.cs b/src/Carbunql.TypeSafe/Extensions/UnaryExpressionExtension.cs index 1ef8b21b..44160dc5 100644 --- a/src/Carbunql.TypeSafe/Extensions/UnaryExpressionExtension.cs +++ b/src/Carbunql.TypeSafe/Extensions/UnaryExpressionExtension.cs @@ -1,5 +1,5 @@ -using System.Linq.Expressions; -using Carbunql.TypeSafe.Building; +using Carbunql.TypeSafe.Building; +using System.Linq.Expressions; namespace Carbunql.TypeSafe.Extensions; diff --git a/src/Carbunql.TypeSafe/FluentSelectQueryBuilder.cs b/src/Carbunql.TypeSafe/FluentSelectQueryBuilder.cs index 1aeb364c..2ee7a42e 100644 --- a/src/Carbunql.TypeSafe/FluentSelectQueryBuilder.cs +++ b/src/Carbunql.TypeSafe/FluentSelectQueryBuilder.cs @@ -1,5 +1,5 @@ -using System.Linq.Expressions; -using Carbunql.TypeSafe.Dialect; +using Carbunql.TypeSafe.Dialect; +using System.Linq.Expressions; namespace Carbunql.TypeSafe; diff --git a/src/Carbunql/Building/SelectQueryExtension.cs b/src/Carbunql/Building/SelectQueryExtension.cs index b928e7f4..951f7e02 100644 --- a/src/Carbunql/Building/SelectQueryExtension.cs +++ b/src/Carbunql/Building/SelectQueryExtension.cs @@ -118,7 +118,7 @@ public static FromClause From(this SelectQuery source, Func builder) /// The constructed common table expression. public static CommonTable With(this SelectQuery source, string query) { - var subQuery = new SelectQuery(query); + var subQuery = SelectQuery.Parse(query); return source.With(subQuery.ToCommonTable("cte")); } diff --git a/src/Carbunql/Fluent/SelectQueryWithExtensions.cs b/src/Carbunql/Fluent/SelectQueryWithExtensions.cs index 32b91bec..d3294a24 100644 --- a/src/Carbunql/Fluent/SelectQueryWithExtensions.cs +++ b/src/Carbunql/Fluent/SelectQueryWithExtensions.cs @@ -4,16 +4,16 @@ namespace Carbunql.Fluent; public static class SelectQueryWithExtensions { - public static SelectQuery With(this SelectQuery sq, string query, string alias) - { - sq.With(query).As(alias); - return sq; - } + public static SelectQuery With(this SelectQuery sq, string query, string alias) + { + sq.With(query).As(alias); + return sq; + } - public static SelectQuery With(this SelectQuery sq, string query, string alias, Materialized type) - { - var ct = sq.With(query).As(alias); - ct.Materialized = type; - return sq; - } + public static SelectQuery With(this SelectQuery sq, string query, string alias, Materialized type) + { + var ct = sq.With(query).As(alias); + ct.Materialized = type; + return sq; + } } diff --git a/src/Carbunql/IEnumerableExtension.cs b/src/Carbunql/IEnumerableExtension.cs index 25f47cf0..03995d74 100644 --- a/src/Carbunql/IEnumerableExtension.cs +++ b/src/Carbunql/IEnumerableExtension.cs @@ -4,83 +4,83 @@ namespace Carbunql; public static class IEnumerableExtension { - public static IEnumerable ForEach(this IEnumerable items, Action action) - { - foreach (var item in items) - { - action(item); - } - return items; - } + public static IEnumerable ForEach(this IEnumerable items, Action action) + { + foreach (var item in items) + { + action(item); + } + return items; + } - /// - /// Gets the root query sources which are not referenced by any other query sources. - /// - public static IEnumerable GetRootsBySource(this IEnumerable querySources) - { - var querySourceList = querySources.OrderByDescending(x => x.MaxLevel).ToList(); + /// + /// Gets the root query sources which are not referenced by any other query sources. + /// + public static IEnumerable GetRootsBySource(this IEnumerable querySources) + { + var querySourceList = querySources.OrderByDescending(x => x.MaxLevel).ToList(); - var rootQuerySources = new List(); - var roots = new List>(); + var rootQuerySources = new List(); + var roots = new List>(); - foreach (var qs in querySourceList) - { - var paths = qs.ToTreePaths(); - var isRoot = true; + foreach (var qs in querySourceList) + { + var paths = qs.ToTreePaths(); + var isRoot = true; - foreach (var root in roots) - { - foreach (var path in paths) - { - if (root.Contains(path.First())) - { - isRoot = false; - } - } - } - if (isRoot) - { - rootQuerySources.Add(qs); - foreach (var path in paths) - { - roots.Add(path); - } - } - } + foreach (var root in roots) + { + foreach (var path in paths) + { + if (root.Contains(path.First())) + { + isRoot = false; + } + } + } + if (isRoot) + { + rootQuerySources.Add(qs); + foreach (var path in paths) + { + roots.Add(path); + } + } + } - return rootQuerySources; - } + return rootQuerySources; + } - /// - /// Retrieves one QuerySource per query. The retrieval order is descending by Level and ascending by Sequence. - /// - /// - /// The source collection of QuerySources. - /// A collection of QuerySources, one per query, ordered by descending Level and ascending Sequence. - public static IEnumerable GetRootsByQuery(this IEnumerable source) where T : IQuerySource - { - return source.GroupBy(ds => ds.Query).Select(ds => ds.OrderByDescending(s => s.MaxLevel).ThenBy(s => s.Index).First()); - } + /// + /// Retrieves one QuerySource per query. The retrieval order is descending by Level and ascending by Sequence. + /// + /// + /// The source collection of QuerySources. + /// A collection of QuerySources, one per query, ordered by descending Level and ascending Sequence. + public static IEnumerable GetRootsByQuery(this IEnumerable source) where T : IQuerySource + { + return source.GroupBy(ds => ds.Query).Select(ds => ds.OrderByDescending(s => s.MaxLevel).ThenBy(s => s.Index).First()); + } - /// - /// Ensures that the enumerable source contains at least one element. - /// Throws an if no elements are found. - /// - /// The type of elements in the enumerable, must implement . - /// The enumerable source to check. - /// The same enumerable source if it contains any elements. - /// Thrown when no elements are found in the enumerable source. - public static IEnumerable EnsureAny(this IEnumerable source, string appendErroressage = "") where T : IQuerySource - { - if (source.Any()) return source; + /// + /// Ensures that the enumerable source contains at least one element. + /// Throws an if no elements are found. + /// + /// The type of elements in the enumerable, must implement . + /// The enumerable source to check. + /// The same enumerable source if it contains any elements. + /// Thrown when no elements are found in the enumerable source. + public static IEnumerable EnsureAny(this IEnumerable source, string appendErroressage = "") where T : IQuerySource + { + if (source.Any()) return source; - if (string.IsNullOrEmpty(appendErroressage)) - { - throw new InvalidOperationException($"No matching QuerySource was found."); - } - else - { - throw new InvalidOperationException($"No matching QuerySource was found. {appendErroressage}"); - } - } + if (string.IsNullOrEmpty(appendErroressage)) + { + throw new InvalidOperationException($"No matching QuerySource was found."); + } + else + { + throw new InvalidOperationException($"No matching QuerySource was found. {appendErroressage}"); + } + } } diff --git a/src/Carbunql/MergeQuery.cs b/src/Carbunql/MergeQuery.cs index 20b2ef1a..4e7012b6 100644 --- a/src/Carbunql/MergeQuery.cs +++ b/src/Carbunql/MergeQuery.cs @@ -28,7 +28,7 @@ public MergeQuery(IReadQuery datasource, string destinationTable, IEnumerable + /// Parses the given SQL query string and returns a corresponding object. + /// + /// The SQL query string to be parsed. + /// A object representing the parsed SQL query. + /// + /// This method utilizes the to interpret the SQL string + /// and construct a object. + /// + public static SelectQuery Parse(string query) + { + return SelectQueryParser.Parse(query); + } + /// /// Initializes a new instance of the class. /// @@ -39,6 +53,7 @@ public SelectQuery() { } /// This constructor parses the provided SQL query string and initializes the select query object with its components, such as SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY clauses. /// The query string may contain additional clauses such as WITH, WINDOW, and LIMIT, which are also parsed and initialized if present. /// + /// Obsolete("This constructor is obsolete. Use the static Parse method instead, e.g., SelectQuery.Parse(query).") public SelectQuery(string query) { var parsedQuery = SelectQueryParser.Parse(query); @@ -1178,7 +1193,7 @@ public SelectQuery AddExists(IEnumerable keyColumnNames, string validati { qs.Query.Where(() => { - var sq = new SelectQuery($"select * from {validationTableName} as x"); + var sq = SelectQuery.Parse($"select * from {validationTableName} as x"); keyColumnNames.ForEach(keyColumn => sq.Where($"x.{keyColumn} = {qs.Alias}.{keyColumn}")); return sq.ToExists(); }); @@ -1209,7 +1224,7 @@ public SelectQuery AddExists(string sourceTableName, IEnumerable keyColu { qs.Query.Where(() => { - var sq = new SelectQuery($"select * from {validationTableName} as x"); + var sq = SelectQuery.Parse($"select * from {validationTableName} as x"); keyColumnNames.ForEach(keyColumn => sq.Where($"x.{keyColumn} = {qs.Alias}.{keyColumn}")); return sq.ToExists(); }); @@ -1236,7 +1251,7 @@ public SelectQuery AddNotExists(IEnumerable keyColumnNames, string valid { qs.Query.Where(() => { - var sq = new SelectQuery($"select * from {validationTableName} as x"); + var sq = SelectQuery.Parse($"select * from {validationTableName} as x"); keyColumnNames.ForEach(keyColumn => sq.Where($"x.{keyColumn} = {qs.Alias}.{keyColumn}")); return sq.ToNotExists(); }); @@ -1266,7 +1281,7 @@ public SelectQuery AddNotExists(string sourceTableName, IEnumerable keyC { qs.Query.Where(() => { - var sq = new SelectQuery($"select * from {validationTableName} as x"); + var sq = SelectQuery.Parse($"select * from {validationTableName} as x"); keyColumnNames.ForEach(keyColumn => sq.Where($"x.{keyColumn} = {qs.Alias}.{keyColumn}")); return sq.ToNotExists(); }); diff --git a/test/Carbunql.Analysis.Test/Demo.cs b/test/Carbunql.Analysis.Test/Demo.cs index 000eca8b..4817e87b 100644 --- a/test/Carbunql.Analysis.Test/Demo.cs +++ b/test/Carbunql.Analysis.Test/Demo.cs @@ -35,7 +35,7 @@ from table_a as a where b.table_a_id is null "; - var q = new SelectQuery(text); + var q = SelectQuery.Parse(text); DebugPrint(q.ToCommand()); } } diff --git a/test/Carbunql.Analysis.Test/EscapedIdentiferTest.cs b/test/Carbunql.Analysis.Test/EscapedIdentiferTest.cs index 32ee9a8e..5d559a9b 100644 --- a/test/Carbunql.Analysis.Test/EscapedIdentiferTest.cs +++ b/test/Carbunql.Analysis.Test/EscapedIdentiferTest.cs @@ -16,7 +16,7 @@ public void Postgres() { var expect = @"SELECT 1 AS ""a b"""; - var sq = new SelectQuery(expect); + var sq = SelectQuery.Parse(expect); Monitor.Log(sq); var lst = sq.GetTokens().ToList(); @@ -32,7 +32,7 @@ public void Oracle() 1 AS ""a b"" FROM dual"; - var sq = new SelectQuery(expect); + var sq = SelectQuery.Parse(expect); Monitor.Log(sq); var lst = sq.GetTokens().ToList(); @@ -46,7 +46,7 @@ public void MySql() { var expect = @"SELECT 1 AS `a b`"; - var sq = new SelectQuery(expect); + var sq = SelectQuery.Parse(expect); Monitor.Log(sq); var lst = sq.GetTokens().ToList(); @@ -60,7 +60,7 @@ public void SQLServer() { var expect = @"SELECT 1 AS [a b]"; - var sq = new SelectQuery(expect); + var sq = SelectQuery.Parse(expect); Monitor.Log(sq); var lst = sq.GetTokens().ToList(); @@ -74,7 +74,7 @@ public void SingleQuoteEscape() { var expect = @"SELECT 'It''s raining' AS ""column name"""; - var sq = new SelectQuery(expect); + var sq = SelectQuery.Parse(expect); Monitor.Log(sq); var lst = sq.GetTokens().ToList(); diff --git a/test/Carbunql.Analysis.Test/SelectQueryParserTest.cs b/test/Carbunql.Analysis.Test/SelectQueryParserTest.cs index f3f7d27e..76ce49b0 100644 --- a/test/Carbunql.Analysis.Test/SelectQueryParserTest.cs +++ b/test/Carbunql.Analysis.Test/SelectQueryParserTest.cs @@ -288,7 +288,7 @@ b as ( from b"; - var item = new SelectQuery(text); + var item = SelectQuery.Parse(text); Monitor.Log(item); var lst = item.GetTokens().ToList(); @@ -638,7 +638,7 @@ union all (((select 4 as v))) ) d"; - var sq = new SelectQuery(text); + var sq = SelectQuery.Parse(text); Monitor.Log(sq); var expect = @"SELECT @@ -678,7 +678,7 @@ union all (((select 4 as v))) ) d"; - var sq = new SelectQuery(text); + var sq = SelectQuery.Parse(text); Monitor.Log(sq); var expect = @"SELECT @@ -714,7 +714,7 @@ public void UnionIssue501_VirtualTableParser2() (select 2 as v) ) d"; - var sq = new SelectQuery(text); + var sq = SelectQuery.Parse(text); Monitor.Log(sq); var expect = @"SELECT diff --git a/test/Carbunql.Analysis.Test/StackOverFlowTest.cs b/test/Carbunql.Analysis.Test/StackOverFlowTest.cs index 87ff8ad7..b7297b72 100644 --- a/test/Carbunql.Analysis.Test/StackOverFlowTest.cs +++ b/test/Carbunql.Analysis.Test/StackOverFlowTest.cs @@ -24,7 +24,7 @@ public void Union_50k() var exception = Record.Exception(() => { - var sq = new SelectQuery(sb.ToString()); + var sq = SelectQuery.Parse(sb.ToString()); sq.GetTokens(); Output.WriteLine(sq.ToText()); diff --git a/test/Carbunql.Benchmark/Program.cs b/test/Carbunql.Benchmark/Program.cs index 532dbb76..3099aed8 100644 --- a/test/Carbunql.Benchmark/Program.cs +++ b/test/Carbunql.Benchmark/Program.cs @@ -108,7 +108,7 @@ private SqModel.SelectQuery GetSqModelQuery() private SelectQuery GetCarbunqlQuery() { - var sq = new SelectQuery(Sql); + var sq = SelectQuery.Parse(Sql); for (int i = 0; i < 100; i++) { sq.AddParameter(":" + i, i); diff --git a/test/Carbunql.Building.Test/CopyTest.cs b/test/Carbunql.Building.Test/CopyTest.cs index 83fe8b17..a960ae3f 100644 --- a/test/Carbunql.Building.Test/CopyTest.cs +++ b/test/Carbunql.Building.Test/CopyTest.cs @@ -15,7 +15,7 @@ public CopyTest(ITestOutputHelper output) [Fact] public void DeepCopy() { - var sq = new SelectQuery("select a.column_1 as c1 from table_a as a"); + var sq = SelectQuery.Parse("select a.column_1 as c1 from table_a as a"); var actual = sq.DeepCopy(); Assert.Equal(sq.ToText().ToValidateText(), actual!.ToText().ToValidateText()); @@ -25,7 +25,7 @@ public void DeepCopy() [Fact] public void Serialize_SelectQuery() { - var sq = new SelectQuery("select a.column_1 as c1 from table_a as a"); + var sq = SelectQuery.Parse("select a.column_1 as c1 from table_a as a"); var json = Serializer.Serialize(sq); var actual = Serializer.Deserialize(json); @@ -36,7 +36,7 @@ public void Serialize_SelectQuery() [Fact] public void Serialize() { - var sq = new SelectQuery("select a.column_1 as c1 from table_a as a"); + var sq = SelectQuery.Parse("select a.column_1 as c1 from table_a as a"); var json = Serializer.Serialize(sq); var actual = Serializer.Deserialize(json); @@ -47,7 +47,7 @@ public void Serialize() //[Fact] //public void DeserializeFromByte() //{ - // var sq = new SelectQuery("select a.column_1 as c1 from table_a as a"); + // var sq = SelectQuery.Parse("select a.column_1 as c1 from table_a as a"); // var json = new byte[] { 146, 0, 154, 144, 145, 146, 146, 6, 147, 192, 161, 97, 168, 99, 111, 108, 117, 109, 110, 95, 49, 162, 99, 49, 146, 147, 146, 1, 148, 194, 192, 167, 116, 97, 98, 108, 101, 95, 97, 192, 161, 97, 192, 192, 192, 192, 192, 192, 192, 192, 128 }; // var actual = Serializer.Deserialize(json); diff --git a/test/Carbunql.Building.Test/DemoBuildDiffQUery.cs b/test/Carbunql.Building.Test/DemoBuildDiffQUery.cs index ecdd7c93..3451113b 100644 --- a/test/Carbunql.Building.Test/DemoBuildDiffQUery.cs +++ b/test/Carbunql.Building.Test/DemoBuildDiffQUery.cs @@ -97,8 +97,8 @@ public void Build() v2"; var keys = new[] { "id" }; - var expectsq = new SelectQuery(expectSql); - var actualsq = new SelectQuery(actualSql); + var expectsq = SelectQuery.Parse(expectSql); + var actualsq = SelectQuery.Parse(actualSql); var sq = DiffQueryBuilder.Execute(expectsq, actualsq, keys); diff --git a/test/Carbunql.Building.Test/FormatTest.cs b/test/Carbunql.Building.Test/FormatTest.cs index 2c01466d..8bfc9d1a 100644 --- a/test/Carbunql.Building.Test/FormatTest.cs +++ b/test/Carbunql.Building.Test/FormatTest.cs @@ -19,7 +19,7 @@ private string GetFormatValidateText(string text) [Fact] public void Issuse280_CreateTable() { - var sq = new SelectQuery("SELECT x.id FROM x"); + var sq = SelectQuery.Parse("SELECT x.id FROM x"); var q = sq.ToCreateTableQuery("test"); Monitor.Log(q); @@ -39,7 +39,7 @@ public void Issuse280_CreateTable() [Fact] public void Issuse280_Union() { - var sq = new SelectQuery("select x.id from x union select y.id from y"); + var sq = SelectQuery.Parse("select x.id from x union select y.id from y"); Monitor.Log(sq); @@ -61,7 +61,7 @@ public void Issuse280_Union() [Fact] public void Issuse280_SubQuery() { - var sq = new SelectQuery("select x.id from (select select y.id from y) as x"); + var sq = SelectQuery.Parse("select x.id from (select select y.id from y) as x"); Monitor.Log(sq); diff --git a/test/Carbunql.Building.Test/GetInternalQueriesTest.cs b/test/Carbunql.Building.Test/GetInternalQueriesTest.cs index 998e4b78..f172d56c 100644 --- a/test/Carbunql.Building.Test/GetInternalQueriesTest.cs +++ b/test/Carbunql.Building.Test/GetInternalQueriesTest.cs @@ -18,7 +18,7 @@ public GetInternalQueriesTest(ITestOutputHelper output) [Fact] public void CountTest() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" with cte_a as ( --index:0 cte query @@ -84,7 +84,7 @@ union all private void InjectUserFilter(SelectQuery sq, string filteredTable, out bool isSuccess) { - var filterQuery = new SelectQuery(@" + var filterQuery = SelectQuery.Parse(@" select userid from @@ -118,7 +118,7 @@ private void InjectUserFilter(SelectQuery sq, string filteredTable, out bool isS [Fact] public void InjectWhereTest() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" select a.* from articles as a order by CreatedOn desc "); @@ -157,7 +157,7 @@ ORDER BY [Fact] public void InjectWhereTest_Joined() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" select c.categoryname , a.* @@ -205,7 +205,7 @@ ORDER BY [Fact] public void InjectWhereTest_SubQuery() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" select a2.* from @@ -256,7 +256,7 @@ ORDER BY [Fact] public void InjectWhereTest_CTE() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" with a2 as ( select a1.* from articles as a1 @@ -311,7 +311,7 @@ ORDER BY [Fact] public void CountTest_SubQuery() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" select * from diff --git a/test/Carbunql.Building.Test/QueryCommandMonitor.cs b/test/Carbunql.Building.Test/QueryCommandMonitor.cs index 8d00df79..f9cf9dab 100644 --- a/test/Carbunql.Building.Test/QueryCommandMonitor.cs +++ b/test/Carbunql.Building.Test/QueryCommandMonitor.cs @@ -1,5 +1,4 @@ -using System.Data; -using Xunit.Abstractions; +using Xunit.Abstractions; namespace Carbunql.Building.Test; diff --git a/test/Carbunql.Building.Test/QuerySourceFilterTest.cs b/test/Carbunql.Building.Test/QuerySourceFilterTest.cs index fa8d7ca0..7ababc23 100644 --- a/test/Carbunql.Building.Test/QuerySourceFilterTest.cs +++ b/test/Carbunql.Building.Test/QuerySourceFilterTest.cs @@ -23,7 +23,7 @@ public void ShowDataSet() from sale as s"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Lv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -48,7 +48,7 @@ public void EqualTest() /* Lv:1, Seq:1, Refs:0-1, Columns:[sale_id, store_id, price] */ sale AS s"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Lv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -99,7 +99,7 @@ public void SubQueryTest() sale AS s1 ) AS s2"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Lv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -152,7 +152,7 @@ INNER JOIN /* Lv:1, Seq:2, Refs:0-2, Columns:[store_id] */ store AS st ON s.store_id = st.store_id"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Lv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -203,7 +203,7 @@ INNER JOIN /* Lv:1, Seq:2, Refs:0-2, Columns:[store_name, store_id] */ store AS st ON s.store_id = st.store_id"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Lv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -265,7 +265,7 @@ sale AS s1 /* Lv:1, Seq:1, Refs:0-1, Columns:[sale_id, store_id, price] */ sx AS s2"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Lv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -339,7 +339,7 @@ ORDER BY c.customer_id, ms.sale_month"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -417,7 +417,7 @@ sales as s var lower_limit = new DateTime(2024, 7, 20); - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .OverrideSelect("journal_date", (source, item) => $"greatest({item}, {source.Query.AddParameter(":lower_limit", lower_limit)})") .AddNotExists(["sale_id"], "sale_journals") .AddWhere("request_timestamp", (source) => $"{source.Alias}.request_timestamp >= :lower_limit") @@ -613,7 +613,7 @@ public void DynamicConditionTest_City_BirthDay() var city = "Tokyo"; DateTime? birthday = new DateTime(1980, 5, 15); - var query = new SelectQuery(SelectCustomers) + var query = SelectQuery.Parse(SelectCustomers) .AddParameter(new QueryParameter(":page_index", pageIndex)); if (!string.IsNullOrEmpty(firstName)) @@ -678,7 +678,7 @@ public void DynamicConditionTest_SaleId_Exists() long? customerId = 1234567890; long? saleId = 9999999; - var query = new SelectQuery(SelectCustomers) + var query = SelectQuery.Parse(SelectCustomers) .AddParameter(new QueryParameter(":page_index", pageIndex)); if (!string.IsNullOrEmpty(firstName)) @@ -750,7 +750,7 @@ public void DynamicConditionTest_SaleId_Join() long? customerId = 1234567890; long? saleId = 9999999; - var query = new SelectQuery(SelectCustomers) + var query = SelectQuery.Parse(SelectCustomers) .AddParameter(new QueryParameter(":page_index", pageIndex)); if (!string.IsNullOrEmpty(firstName)) @@ -817,7 +817,7 @@ public void DynamicConditionTest_StoreName_Exists() long? customerId = 1234567890; var storeName = "Osaka"; - var query = new SelectQuery(SelectCustomers) + var query = SelectQuery.Parse(SelectCustomers) .AddParameter(new QueryParameter(":page_index", pageIndex)); if (!string.IsNullOrEmpty(storeName)) @@ -907,7 +907,7 @@ public void DynamicConditionTest() var city = "Tokyo"; DateTime? birthday = new DateTime(1980, 5, 15); - var query = new SelectQuery(SelectCustomers) + var query = SelectQuery.Parse(SelectCustomers) .AddParameter(new QueryParameter(":page_index", pageIndex)); // add CTE @@ -1009,7 +1009,7 @@ sale as s ) d """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .Equal("id", 1); Monitor.Log(query, exportTokens: false); @@ -1047,7 +1047,7 @@ sale as s ) d """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .Equal("sale_id", 1); Monitor.Log(query, exportTokens: false); @@ -1085,7 +1085,7 @@ sale as s ) d """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .Equal("price", 10); Monitor.Log(query, exportTokens: false); @@ -1123,7 +1123,7 @@ sale as s ) d """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .Equal("d", "sale_id", 1); Monitor.Log(query, exportTokens: false); @@ -1155,7 +1155,7 @@ public void OrderByTest() sale as s """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .OrderBy("unit_price"); Monitor.Log(query, exportTokens: false); @@ -1182,7 +1182,7 @@ public void OrderByTest_Alias() sale as s """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .OrderBy("price"); Monitor.Log(query, exportTokens: false); @@ -1209,7 +1209,7 @@ s.sale_date as journal_date sale as s """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .OverrideSelect("journal_date", (sourse, col) => $"greatest({col}, :lower_limit)"); Monitor.Log(query, exportTokens: false); @@ -1234,7 +1234,7 @@ s.sale_date as journal_date sale as s """; - var query = new SelectQuery(sql) + var query = SelectQuery.Parse(sql) .Greatest("journal_date", ":lower_limit"); Monitor.Log(query, exportTokens: false); diff --git a/test/Carbunql.Building.Test/QuerySourceTest.cs b/test/Carbunql.Building.Test/QuerySourceTest.cs index a9cd4cc0..1469b1bd 100644 --- a/test/Carbunql.Building.Test/QuerySourceTest.cs +++ b/test/Carbunql.Building.Test/QuerySourceTest.cs @@ -24,7 +24,7 @@ public void Simple() from sale as s"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -59,7 +59,7 @@ sale as s where s.store_id = 1"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -92,7 +92,7 @@ sale as s order by s.store_id = 1"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -126,7 +126,7 @@ sale as s group by s.store_id"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -161,7 +161,7 @@ group by having sum(s.price) = 0"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -199,7 +199,7 @@ sale as s --but they can be identified because there is no table join. store_id = 1"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -236,7 +236,7 @@ sale as s --Although the SQL is correct, it cannot be parsed by the library. sale_id = 1"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); var exception = Assert.Throws(() => { @@ -267,7 +267,7 @@ public void SubQueryTest() sale AS s ) AS d"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -400,7 +400,7 @@ ORDER BY ms.month, ms.product_id"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -451,7 +451,7 @@ sale AS s WHERE s.sale_id = 3"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -525,7 +525,7 @@ sale AS s ) AS d ) AS q"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -606,7 +606,7 @@ store AS st st.store_id = 1 "; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -705,7 +705,7 @@ ORDER BY r.customer_id, r.sale_month"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -868,7 +868,7 @@ INNER JOIN ORDER BY line_id"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1076,7 +1076,7 @@ ORDER BY ms.month, ms.product_id"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, MaxLv:{x.MaxLevel}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1103,7 +1103,7 @@ sales as ( from sales"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1145,7 +1145,7 @@ sales s where exists (select * from dat x where x.sale_id = s.sale_id) --use wildcard"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1192,7 +1192,7 @@ sales s --has not relationship where not exists (select dat.v1 from dat where x.sale_id = s.sale_id) --use wildcard"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1235,7 +1235,7 @@ GROUP BY customer_id, DATE_TRUNC('month', sale_date)"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1273,7 +1273,7 @@ sale s where exists (select * from target x where x.sale_id = s.sale_id)"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1345,7 +1345,7 @@ sale_journals AS x FROM final AS f"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1404,7 +1404,7 @@ FROM employees ELSE salary > 60000 END"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); @@ -1448,7 +1448,7 @@ public void CurrentTimestampTest() sale s inner join product p on s.product_id = p.product_id"; - var query = new SelectQuery(sql); + var query = SelectQuery.Parse(sql); query.GetQuerySources().ForEach(x => { x.AddSourceComment($"Index:{x.Index}, Alias:{x.Alias}, MaxLv:{x.MaxLevel}, SourceType:{x.SourceType}, Columns:[{string.Join(", ", x.ColumnNames)}]"); diff --git a/test/Carbunql.Building.Test/SelectItemTest.cs b/test/Carbunql.Building.Test/SelectItemTest.cs index ad591d6c..43f1cbaf 100644 --- a/test/Carbunql.Building.Test/SelectItemTest.cs +++ b/test/Carbunql.Building.Test/SelectItemTest.cs @@ -176,8 +176,8 @@ public void CaseWhenTest() [Fact] public void SubQuerySelectAll() { - var query_a = new SelectQuery("select table_a_id, v1, v2 from table_a"); - var query_b = new SelectQuery("select table_b_id, table_a_id, v11, v12 from table_b"); + var query_a = SelectQuery.Parse("select table_a_id, v1, v2 from table_a"); + var query_b = SelectQuery.Parse("select table_b_id, table_a_id, v11, v12 from table_b"); var sq = new SelectQuery(); var (f, a) = sq.From(query_a).As("a"); @@ -200,8 +200,8 @@ public void SubQuerySelectAll() [Fact] public void SubQuerySelectAll_override() { - var query_a = new SelectQuery("select table_a_id, v1, v2 from table_a"); - var query_b = new SelectQuery("select table_b_id, table_a_id, v11, v12 from table_b"); + var query_a = SelectQuery.Parse("select table_a_id, v1, v2 from table_a"); + var query_b = SelectQuery.Parse("select table_b_id, table_a_id, v11, v12 from table_b"); var sq = new SelectQuery(); var (f, a) = sq.From(query_a).As("a"); diff --git a/test/Carbunql.Building.Test/SerializeTest.Clause.cs b/test/Carbunql.Building.Test/SerializeTest.Clause.cs index 6dd0fb61..390d2b6f 100644 --- a/test/Carbunql.Building.Test/SerializeTest.Clause.cs +++ b/test/Carbunql.Building.Test/SerializeTest.Clause.cs @@ -147,7 +147,7 @@ public void OrderClause() [Fact] public void CommonTable() { - var sq = new CommonTable(new VirtualTable(new SelectQuery("select 1")), "a", new ValueCollection(new[] { "v1" })); + var sq = new CommonTable(new VirtualTable(SelectQuery.Parse("select 1")), "a", new ValueCollection(new[] { "v1" })); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); @@ -191,7 +191,7 @@ public void WithClause() { var sq = new WithClause() { - new CommonTable(new VirtualTable(new SelectQuery("select 1")), "a", new ValueCollection(new[] { "v1" })) + new CommonTable(new VirtualTable(SelectQuery.Parse("select 1")), "a", new ValueCollection(new[] { "v1" })) }; var json = MessagePackSerializer.Serialize(sq); diff --git a/test/Carbunql.Building.Test/SerializeTest.Query.cs b/test/Carbunql.Building.Test/SerializeTest.Query.cs index c1e288ab..99dedf38 100644 --- a/test/Carbunql.Building.Test/SerializeTest.Query.cs +++ b/test/Carbunql.Building.Test/SerializeTest.Query.cs @@ -6,9 +6,9 @@ namespace Carbunql.Building.Test; public partial class SerializeTest { [Fact] - public void SelectQuery() + public void SelectQueryTest() { - var sq = new SelectQuery("select a.column_1 as c1 from table_a as a"); + var sq = SelectQuery.Parse("select a.column_1 as c1 from table_a as a"); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); @@ -22,7 +22,7 @@ public void SelectQuery() [Fact] public void JoinQuery() { - var sq = new SelectQuery("select a.* from table_a as a inner join table_b as b on a.id = b.id"); + var sq = SelectQuery.Parse("select a.* from table_a as a inner join table_b as b on a.id = b.id"); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); @@ -36,7 +36,7 @@ public void JoinQuery() [Fact] public void OperatableQuery() { - var sq = new OperatableQuery("union", new SelectQuery("select 1")); + var sq = new OperatableQuery("union", SelectQuery.Parse("select 1")); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); @@ -50,7 +50,7 @@ public void OperatableQuery() [Fact] public void UnionQuery() { - var sq = new SelectQuery("select 1 as v1 union select 2 as v1 union all select 3 as v1"); + var sq = SelectQuery.Parse("select 1 as v1 union select 2 as v1 union all select 3 as v1"); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); @@ -102,7 +102,7 @@ public void ValuesQuery() [Fact] public void SampleQuery() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" WITH dat ( line_id, name, unit_price, quantity, tax_rate @@ -202,7 +202,7 @@ ORDER BY [Fact] public void SampleQuery_WindowFunction() { - var sq = new SelectQuery(@" + var sq = SelectQuery.Parse(@" with v (id, name, value) as ( values @@ -236,7 +236,7 @@ SELECT sum(salary) OVER w, avg(salary) OVER w FROM empsalary WINDOW w AS (PARTITION BY depname ORDER BY salary DESC) "; - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); diff --git a/test/Carbunql.Building.Test/SerializeTest.TableBase.cs b/test/Carbunql.Building.Test/SerializeTest.TableBase.cs index 3880953e..feb04391 100644 --- a/test/Carbunql.Building.Test/SerializeTest.TableBase.cs +++ b/test/Carbunql.Building.Test/SerializeTest.TableBase.cs @@ -22,7 +22,7 @@ public void PhysicalTable() [Fact] public void VirtualTable() { - var sq = new VirtualTable(new SelectQuery("select 1")); + var sq = new VirtualTable(SelectQuery.Parse("select 1")); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); diff --git a/test/Carbunql.Building.Test/SerializeTest.ValueBase.cs b/test/Carbunql.Building.Test/SerializeTest.ValueBase.cs index e5c5784c..20e2667b 100644 --- a/test/Carbunql.Building.Test/SerializeTest.ValueBase.cs +++ b/test/Carbunql.Building.Test/SerializeTest.ValueBase.cs @@ -216,7 +216,7 @@ public void ParameterValue() [Fact] public void QueryContainer() { - var sq = new QueryContainer(new SelectQuery("select 1")); + var sq = new QueryContainer(SelectQuery.Parse("select 1")); var json = MessagePackSerializer.Serialize(sq); Output.WriteLine(MessagePackSerializer.ConvertToJson(json)); diff --git a/test/Carbunql.Building.Test/ToCTETest.cs b/test/Carbunql.Building.Test/ToCTETest.cs index caf83f2e..0f0bbebd 100644 --- a/test/Carbunql.Building.Test/ToCTETest.cs +++ b/test/Carbunql.Building.Test/ToCTETest.cs @@ -14,7 +14,7 @@ public ToCTETest(ITestOutputHelper output) [Fact] public void Old() { - var tmp = new SelectQuery("with x as (select id, val from table_a as a) select x.id from x"); + var tmp = SelectQuery.Parse("with x as (select id, val from table_a as a) select x.id from x"); //Convert select query to Common table //Return value is SelectQuery class and CommonTable class diff --git a/test/Carbunql.Building.Test/ToTextTest.cs b/test/Carbunql.Building.Test/ToTextTest.cs index d2fc6f3f..78ce6d5c 100644 --- a/test/Carbunql.Building.Test/ToTextTest.cs +++ b/test/Carbunql.Building.Test/ToTextTest.cs @@ -25,7 +25,7 @@ public void ToText() :value = 'test' */ select a.column_1 as c1 from table_a as a"; - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); sq.AddParameter(":id", 1); sq.AddParameter(":value", "test"); @@ -44,7 +44,7 @@ public void ToOneLineText() :value = 'test' */ select a.column_1 as c1 from table_a as a"; - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); sq.AddParameter(":id", 1); sq.AddParameter(":value", "test"); @@ -143,11 +143,11 @@ detail AS d ) AS q ORDER BY line_id"; - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); Output.WriteLine(sq.ToText()); Output.WriteLine(sq.ToOneLineText()); - var sq2 = new SelectQuery(sq.ToOneLineCommand().CommandText); + var sq2 = SelectQuery.Parse(sq.ToOneLineCommand().CommandText); Assert.Equal(sql, sq2.ToCommand().CommandText); } } diff --git a/test/Carbunql.Dapper.Test/DapperTest.cs b/test/Carbunql.Dapper.Test/DapperTest.cs index cdf19061..20929344 100644 --- a/test/Carbunql.Dapper.Test/DapperTest.cs +++ b/test/Carbunql.Dapper.Test/DapperTest.cs @@ -32,7 +32,7 @@ public void ExecuteReader_NoParamter() data_ds "; - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); using var r = cn.ExecuteReader(sq); var cnt = 0; while (r.Read()) @@ -63,7 +63,7 @@ public void ExecuteReader_HasParamter() c1 = :val "; - var sq = new SelectQuery(sql); + var sq = SelectQuery.Parse(sql); sq.AddParameter(":val", 1); using var r = cn.ExecuteReader(sq); diff --git a/test/Carbunql.DynamicQuery.Test/UnitTest1.cs b/test/Carbunql.DynamicQuery.Test/UnitTest1.cs index 12f8a7e6..75476c37 100644 --- a/test/Carbunql.DynamicQuery.Test/UnitTest1.cs +++ b/test/Carbunql.DynamicQuery.Test/UnitTest1.cs @@ -18,7 +18,7 @@ public UnitTest1(ITestOutputHelper output) public void AddCondition(int? parameter) { //sql parse - var sq = new SelectQuery(@"select a.a_id, a.val from table as a"); + var sq = SelectQuery.Parse(@"select a.a_id, a.val from table as a"); //get FROM table var a = sq.FromClause!.Root; @@ -53,7 +53,7 @@ table AS a public void AddCondition_ValueParse(int? parameter) { //sql parse - var sq = new SelectQuery(@"select a.a_id, a.val from table as a"); + var sq = SelectQuery.Parse(@"select a.a_id, a.val from table as a"); //get FROM table var a = sq.FromClause!.Root; @@ -87,7 +87,7 @@ table AS a public void AddConditions() { //sql parse - var sq = new SelectQuery(@"select a.a_id, a.val1, a.val2 from table as a"); + var sq = SelectQuery.Parse(@"select a.a_id, a.val1, a.val2 from table as a"); //get FROM table var a = sq.FromClause!.Root; @@ -118,7 +118,7 @@ table AS a public void AddOrCondition(int prm1, int prm2) { //sql parse - var sq = new SelectQuery(@"select a.a_id, a.val from table as a"); + var sq = SelectQuery.Parse(@"select a.a_id, a.val from table as a"); //get FROM table var a = sq.FromClause!.Root; @@ -162,7 +162,7 @@ table AS a public void SelectColumnFilter(params string[] columns) { //sql parse - var sq = new SelectQuery(@"select a.a_id, a.val1, a.val2, a.val2 as val3 from table as a"); + var sq = SelectQuery.Parse(@"select a.a_id, a.val1, a.val2, a.val2 as val3 from table as a"); //get FROM table var a = sq.FromClause!.Root; @@ -191,7 +191,7 @@ table AS a public void SelectColumnFilter_Remove(params string[] columns) { //sql parse - var sq = new SelectQuery(@"select a.a_id, a.val1, a.val2, a.val2 as val3 from table as a"); + var sq = SelectQuery.Parse(@"select a.a_id, a.val1, a.val2, a.val2 as val3 from table as a"); //filter in sq.SelectClause!.FilterInColumns(columns); @@ -213,7 +213,7 @@ table AS a public void AddOutJoinFilter() { //sql parse - var sq = new SelectQuery(@"select a.a_id, a.val from table as a"); + var sq = SelectQuery.Parse(@"select a.a_id, a.val from table as a"); //get FROM table var a = sq.FromClause!.Root; @@ -244,7 +244,7 @@ b.a_id IS null public void AddConnditionToCommonTableExpression() { //sql parse - var sq = new SelectQuery(@"with + var sq = SelectQuery.Parse(@"with cte as ( select a_id, val from table ) diff --git a/test/Carbunql.Postgres.Test/Linq/CommonTableInfoParserTest.cs b/test/Carbunql.Postgres.Test/Linq/CommonTableInfoParserTest.cs index fbfd925b..a49c0d68 100644 --- a/test/Carbunql.Postgres.Test/Linq/CommonTableInfoParserTest.cs +++ b/test/Carbunql.Postgres.Test/Linq/CommonTableInfoParserTest.cs @@ -56,7 +56,7 @@ table_a AS a [Fact] public void SelectQueryCommonTableTest() { - var preset = new SelectQuery("select x.a_id, x.value, x.text from table_x as x where x.a_id = 1"); + var preset = SelectQuery.Parse("select x.a_id, x.value, x.text from table_x as x where x.a_id = 1"); var query = from cte in CommonTable(preset) from x in FromTable(cte) diff --git a/test/Carbunql.Postgres.Test/Linq/JoinTableInfoParserTest.cs b/test/Carbunql.Postgres.Test/Linq/JoinTableInfoParserTest.cs index 9da1b126..839a08c0 100644 --- a/test/Carbunql.Postgres.Test/Linq/JoinTableInfoParserTest.cs +++ b/test/Carbunql.Postgres.Test/Linq/JoinTableInfoParserTest.cs @@ -133,8 +133,8 @@ category AS sub_c [Fact] public void InnerJoinSelectQueryTest() { - var articleQuery = new SelectQuery("select x.article_id, x.category_id, x.article_name, x.price from table_x as x where x.article_id = 1"); - var categoryQuery = new SelectQuery("select y.category_id, y.category_name from table_y as y where y.category_id = 2"); + var articleQuery = SelectQuery.Parse("select x.article_id, x.category_id, x.article_name, x.price from table_x as x where x.article_id = 1"); + var categoryQuery = SelectQuery.Parse("select y.category_id, y.category_name from table_y as y where y.category_id = 2"); var query = from s in FromTable() from a in InnerJoinTable
(articleQuery, x => s.article_id == x.article_id) diff --git a/test/Carbunql.Postgres.Test/Linq/TableInfoParserTest.cs b/test/Carbunql.Postgres.Test/Linq/TableInfoParserTest.cs index bbcf6986..212af82f 100644 --- a/test/Carbunql.Postgres.Test/Linq/TableInfoParserTest.cs +++ b/test/Carbunql.Postgres.Test/Linq/TableInfoParserTest.cs @@ -136,7 +136,7 @@ table_a as a [Fact] public void SelectQueryClassTest() { - var preset = new SelectQuery("select x.a_id, x.value, x.text from table_x as x where x.a_id = 1"); + var preset = SelectQuery.Parse("select x.a_id, x.value, x.text from table_x as x where x.a_id = 1"); var query = from a in FromTable(preset) select a; diff --git a/test/Carbunql.Postgres.Test/SubQueryText.cs b/test/Carbunql.Postgres.Test/SubQueryText.cs index 80e5fbd4..1789b556 100644 --- a/test/Carbunql.Postgres.Test/SubQueryText.cs +++ b/test/Carbunql.Postgres.Test/SubQueryText.cs @@ -70,7 +70,7 @@ a.a_id AS id public void SubQueryTest() { var sq = new SelectQuery(); - var (from, a) = sq.From(new SelectQuery("select * from table_a")).As("a"); ; + var (from, a) = sq.From(SelectQuery.Parse("select * from table_a")).As("a"); ; sq.Select("a", "a_id"); sq.Select(nameof(a), "a_id");