Skip to content

Commit

Permalink
Enhancement: Added build method to SelectQuery class.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mk3008 committed Aug 27, 2024
1 parent d03e770 commit 7fb59f4
Show file tree
Hide file tree
Showing 61 changed files with 271 additions and 257 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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();
```

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
```

Expand All @@ -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);
```

Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/CTEQuery.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<RadzenTabsItem Text="Source">
<RadzenText Style="font-family: 'Ricty Diminished', SFMono-Regular, Consolas, 'Courier New', 'BIZ UDGothic', Meiryo, monospace; font-size: 18px; white-space: pre;" ReadOnly="true" >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();</RadzenText>
</RadzenTabsItem>
Expand Down Expand Up @@ -116,7 +116,7 @@ ORDER BY
}
try
{
fsql = new SelectQuery(sql)
fsql = SelectQuery.Parse(sql)
.ToCTEQuery(name.Trim(), alias.Trim())
.ToText();
}
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/ColumnNameList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -82,7 +82,7 @@ from
}
try
{
var sq = new SelectQuery(sql);
var sq = SelectQuery.Parse(sql);
var sb = new StringBuilder();

fsql = string.Empty;
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/Count.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);";

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/CreateTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);";

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion demo/CarbunqlWeb/Pages/Delete.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);";

Expand Down
2 changes: 1 addition & 1 deletion demo/CarbunqlWeb/Pages/Insert.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);";

Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/InternalQueryList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -149,7 +149,7 @@ order by
}
try
{
var sq = new SelectQuery(sql);
var sq = SelectQuery.Parse(sql);
var sb = new StringBuilder();

fsql = string.Empty;
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/Merge.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/PhysicalTableList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/QuerySource/EnsureAny.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/QuerySource/FilterColumn.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/QuerySource/FilterTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/QuerySource/Labels.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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 =>
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/SelectableItemList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -82,7 +82,7 @@ from
}
try
{
var sq = new SelectQuery(sql);
var sq = SelectQuery.Parse(sql);
var sb = new StringBuilder();

fsql = string.Empty;
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/SelectableTableList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/SubQuery.razor
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<RadzenTabsItem Text="Source">
<RadzenText Style="font-family: 'Ricty Diminished', SFMono-Regular, Consolas, 'Courier New', 'BIZ UDGothic', Meiryo, monospace; font-size: 18px; white-space: pre;" ReadOnly="true" >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();</RadzenText>
</RadzenTabsItem>
Expand Down Expand Up @@ -109,7 +109,7 @@ ORDER BY
}
try
{
fsql = new SelectQuery(sql)
fsql = SelectQuery.Parse(sql)
.ToSubQuery(alias)
.ToText();
}
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/TokenList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -82,7 +82,7 @@ from
}
try
{
var sq = new SelectQuery(sql);
var sq = SelectQuery.Parse(sql);
var sb = new StringBuilder();

fsql = string.Empty;
Expand Down
4 changes: 2 additions & 2 deletions demo/CarbunqlWeb/Pages/Update.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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);";

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion demo/DynamicColumn/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static string GenerateCustomReportQuery(List<string> columns)
""";

// Convert the query to an object
var sq = new SelectQuery(sql);
var sq = SelectQuery.Parse(sql);

// Restrict the selected columns
sq.FilterInColumns(columns);
Expand Down
2 changes: 1 addition & 1 deletion demo/DynamicFiltering/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion demo/Filtering/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Carbunql;
using Carbunql.TypeSafe;
using Carbunql.Building;
using Carbunql.TypeSafe;

internal class Program
{
Expand Down
2 changes: 1 addition & 1 deletion demo/Parse/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down
Loading

0 comments on commit 7fb59f4

Please sign in to comment.