diff --git a/src/Carbunql/AlterTableQuery.cs b/src/Carbunql/AlterTableQuery.cs index cb8ad5cb..40f59889 100644 --- a/src/Carbunql/AlterTableQuery.cs +++ b/src/Carbunql/AlterTableQuery.cs @@ -65,8 +65,8 @@ public List Disassemble() public bool TrySet(TableDefinitionClause clause) { - if (AlterTableClause.Items.Count != 1) throw new InvalidOperationException(); - var cmd = AlterTableClause.Items[0]; + if (AlterTableClause.Count != 1) throw new InvalidOperationException(); + var cmd = AlterTableClause[0]; return cmd.TrySet(clause); } diff --git a/src/Carbunql/Building/ReadQueryExtension.cs b/src/Carbunql/Building/ReadQueryExtension.cs index 3566c8ca..f6d79921 100644 --- a/src/Carbunql/Building/ReadQueryExtension.cs +++ b/src/Carbunql/Building/ReadQueryExtension.cs @@ -165,14 +165,14 @@ public static CreateTableQuery ToCreateTableQuery(this IReadQuery source, TableB /// The SelectableTable representing the IReadQuery for insertion into the specified table. public static SelectableTable ToInsertTable(this IReadQuery source, string table) { - var s = source.GetSelectClause(); - if (s == null) + var clause = source.GetSelectClause(); + if (clause == null) { return new SelectableTable(new PhysicalTable(table), table); } var vals = new ValueCollection(); - foreach (var item in s.Items) + foreach (var item in clause) { vals.Add(new ColumnValue(item.Alias)); } @@ -308,8 +308,8 @@ public static UpdateQuery ToUpdateQuery(this IReadQuery source, SelectableTable /// private static SetClause ToSetClause(this IReadQuery source, IEnumerable keys, string queryAlias) { - var s = source.GetSelectClause() ?? throw new NotSupportedException("select clause is not found."); - var cols = s.Items.Where(x => !keys.Contains(x.Alias)).Select(x => x.Alias).ToList(); + var selectclause = source.GetSelectClause() ?? throw new NotSupportedException("select clause is not found."); + var cols = selectclause.Where(x => !keys.Contains(x.Alias)).Select(x => x.Alias).ToList(); var clause = new SetClause(); foreach (var item in cols) @@ -407,7 +407,7 @@ private static WhereClause ToWhereClauseAsDelete(this IReadQuery source, IEnumer private static WhereClause ToWhereClauseAsDelete(this IReadQuery source, string alias) { var select = source.GetSelectClause(); - var selectColumns = select!.Items!.Select(x => x.Alias); + var selectColumns = select!.Select(x => x.Alias); if (selectColumns == null || !selectColumns.Any()) throw new InvalidOperationException("Missing select clause."); diff --git a/src/Carbunql/Clauses/AlterTableClause.cs b/src/Carbunql/Clauses/AlterTableClause.cs index e95fe4ba..c65ce252 100644 --- a/src/Carbunql/Clauses/AlterTableClause.cs +++ b/src/Carbunql/Clauses/AlterTableClause.cs @@ -3,14 +3,26 @@ namespace Carbunql.Clauses; +/// +/// Represents a clause for altering a table structure. +/// public class AlterTableClause : QueryCommandCollection, IQueryCommandable, ITable { + /// + /// Initializes a new instance of the class with the specified table. + /// + /// The table to be altered. public AlterTableClause(ITable t) { Schema = t.Schema; Table = t.Table; } + /// + /// Initializes a new instance of the class with the specified table and command. + /// + /// The table to be altered. + /// The alteration command. public AlterTableClause(ITable t, IAlterCommand command) { Schema = t.Schema; @@ -18,6 +30,11 @@ public AlterTableClause(ITable t, IAlterCommand command) Items.Add(command); } + /// + /// Initializes a new instance of the class with the specified table and constraint. + /// + /// The table to be altered. + /// The constraint to be added. public AlterTableClause(ITable t, IConstraint constraint) { Schema = t.Schema; @@ -25,39 +42,65 @@ public AlterTableClause(ITable t, IConstraint constraint) Items.Add(new AddConstraintCommand(constraint)); } + /// + /// Initializes a new instance of the class with the specified schema and table. + /// + /// The schema of the table to be altered. + /// The table to be altered. public AlterTableClause(string schema, string table) { Schema = schema; Table = table; } + /// + /// Initializes a new instance of the class with the specified table name. + /// + /// The table to be altered. public AlterTableClause(string table) { Schema = string.Empty; Table = table; } + /// + /// Gets or sets the schema of the table to be altered. + /// public string Schema { get; init; } + /// + /// Gets or sets the name of the table to be altered. + /// public string Table { get; init; } + /// + /// Gets the full name of the table to be altered. + /// public string TableFullName => (string.IsNullOrEmpty(Schema)) ? Table : Schema + "." + Table; + /// + /// Gets the internal queries associated with this clause. + /// public IEnumerable GetInternalQueries() { yield break; } + /// + /// Gets the physical tables associated with this clause. + /// public IEnumerable GetPhysicalTables() { yield break; } + /// + /// Gets the tokens representing this clause. + /// public override IEnumerable GetTokens(Token? parent) { if (!Items.Any()) throw new InvalidOperationException(); - var altertable = Token.Reserved(this, parent, "alter table"); yield return altertable; yield return new Token(this, parent, TableFullName); @@ -68,8 +111,11 @@ public override IEnumerable GetTokens(Token? parent) } } + /// + /// Gets the common tables associated with this clause. + /// public IEnumerable GetCommonTables() { yield break; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/AtTimeZoneClause.cs b/src/Carbunql/Clauses/AtTimeZoneClause.cs index d94d46e6..2cff0a96 100644 --- a/src/Carbunql/Clauses/AtTimeZoneClause.cs +++ b/src/Carbunql/Clauses/AtTimeZoneClause.cs @@ -3,25 +3,45 @@ namespace Carbunql.Clauses; +/// +/// Represents a clause for specifying the time zone for a datetime value. +/// [MessagePackObject(keyAsPropertyName: true)] public class AtTimeZoneClause : ValueBase { + /// + /// Initializes a new instance of the class. + /// public AtTimeZoneClause() { Value = null!; TimeZone = null!; } + /// + /// Initializes a new instance of the class with the specified value and time zone. + /// + /// The datetime value. + /// The time zone. public AtTimeZoneClause(ValueBase value, ValueBase timeZone) { Value = value; TimeZone = timeZone; } + /// + /// Gets or sets the datetime value. + /// public ValueBase Value { get; init; } + /// + /// Gets or sets the time zone. + /// public ValueBase TimeZone { get; init; } + /// + /// Gets the internal queries associated with this clause. + /// protected override IEnumerable GetInternalQueriesCore() { foreach (var item in Value.GetInternalQueries()) @@ -34,6 +54,9 @@ protected override IEnumerable GetInternalQueriesCore() } } + /// + /// Gets the tokens representing this clause. + /// public override IEnumerable GetCurrentTokens(Token? parent) { foreach (var item in Value.GetTokens(parent)) yield return item; @@ -42,6 +65,9 @@ public override IEnumerable GetCurrentTokens(Token? parent) foreach (var item in TimeZone.GetTokens(parent)) yield return item; } + /// + /// Gets the parameters associated with this clause. + /// protected override IEnumerable GetParametersCore() { foreach (var item in Value.GetParameters()) @@ -54,6 +80,9 @@ protected override IEnumerable GetParametersCore() } } + /// + /// Gets the physical tables associated with this clause. + /// protected override IEnumerable GetPhysicalTablesCore() { foreach (var item in Value.GetPhysicalTables()) @@ -66,6 +95,9 @@ protected override IEnumerable GetPhysicalTablesCore() } } + /// + /// Gets the common tables associated with this clause. + /// protected override IEnumerable GetCommonTablesCore() { foreach (var item in Value.GetCommonTables()) @@ -77,4 +109,4 @@ protected override IEnumerable GetCommonTablesCore() yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/BetweenClause.cs b/src/Carbunql/Clauses/BetweenClause.cs index 5b2ba601..07169188 100644 --- a/src/Carbunql/Clauses/BetweenClause.cs +++ b/src/Carbunql/Clauses/BetweenClause.cs @@ -3,9 +3,15 @@ namespace Carbunql.Clauses; +/// +/// Represents a BETWEEN clause in SQL. +/// [MessagePackObject(keyAsPropertyName: true)] public class BetweenClause : ValueBase { + /// + /// Initializes a new instance of the class. + /// public BetweenClause() { Value = null!; @@ -14,6 +20,13 @@ public BetweenClause() IsNegative = false; } + /// + /// Initializes a new instance of the class with the specified value, start, end, and negativity. + /// + /// The value to compare. + /// The start of the range. + /// The end of the range. + /// Specifies whether the BETWEEN clause is negated. public BetweenClause(ValueBase value, ValueBase start, ValueBase end, bool isNegative) { Value = value; @@ -22,14 +35,29 @@ public BetweenClause(ValueBase value, ValueBase start, ValueBase end, bool isNeg IsNegative = isNegative; } + /// + /// Gets or sets the value to compare. + /// public ValueBase Value { get; init; } + /// + /// Gets or sets the start of the range. + /// public ValueBase Start { get; init; } + /// + /// Gets or sets the end of the range. + /// public ValueBase End { get; init; } + /// + /// Gets or sets a value indicating whether the BETWEEN clause is negated. + /// public bool IsNegative { get; init; } + /// + /// Gets the internal queries associated with this clause. + /// protected override IEnumerable GetInternalQueriesCore() { foreach (var item in Value.GetInternalQueries()) @@ -46,6 +74,9 @@ protected override IEnumerable GetInternalQueriesCore() } } + /// + /// Gets the parameters associated with this clause. + /// protected override IEnumerable GetParametersCore() { foreach (var item in Value.GetParameters()) @@ -62,6 +93,9 @@ protected override IEnumerable GetParametersCore() } } + /// + /// Gets the physical tables associated with this clause. + /// protected override IEnumerable GetPhysicalTablesCore() { foreach (var item in Value.GetPhysicalTables()) @@ -78,6 +112,9 @@ protected override IEnumerable GetPhysicalTablesCore() } } + /// + /// Gets the common tables associated with this clause. + /// protected override IEnumerable GetCommonTablesCore() { foreach (var item in Value.GetCommonTables()) @@ -94,6 +131,9 @@ protected override IEnumerable GetCommonTablesCore() } } + /// + /// Gets the tokens representing this clause. + /// public override IEnumerable GetCurrentTokens(Token? parent) { foreach (var item in Value.GetTokens(parent)) yield return item; @@ -105,4 +145,4 @@ public override IEnumerable GetCurrentTokens(Token? parent) yield return Token.Reserved(this, parent, "and"); foreach (var item in End.GetTokens(parent)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/CommentClause.cs b/src/Carbunql/Clauses/CommentClause.cs index 03ccf759..e63b6bbd 100644 --- a/src/Carbunql/Clauses/CommentClause.cs +++ b/src/Carbunql/Clauses/CommentClause.cs @@ -3,61 +3,111 @@ namespace Carbunql.Clauses; +/// +/// Represents a collection of SQL comments. +/// public class CommentClause : IList, IQueryCommandable { + /// + /// Gets or sets the comment at the specified index. + /// public string this[int index] { get => ((IList)Collection)[index]; set => ((IList)Collection)[index] = value; } + /// + /// Gets the number of comments in the collection. + /// public int Count => ((ICollection)Collection).Count; + /// + /// Gets a value indicating whether the collection is read-only. + /// public bool IsReadOnly => ((ICollection)Collection).IsReadOnly; private List Collection { get; set; } = new(); + /// + /// Adds a comment to the collection. + /// public void Add(string item) { ((ICollection)Collection).Add(item); } + /// + /// Removes all comments from the collection. + /// public void Clear() { ((ICollection)Collection).Clear(); } + /// + /// Determines whether the collection contains a specific comment. + /// public bool Contains(string item) { return ((ICollection)Collection).Contains(item); } + /// + /// Copies the elements of the collection to an array, starting at a particular array index. + /// public void CopyTo(string[] array, int arrayIndex) { ((ICollection)Collection).CopyTo(array, arrayIndex); } - public IEnumerable GetCommonTables() + /// + /// Returns an enumerator that iterates through the collection. + /// + public IEnumerator GetEnumerator() { - yield break; + return ((IEnumerable)Collection).GetEnumerator(); } - public IEnumerator GetEnumerator() + /// + /// Returns an enumerator that iterates through the collection. + /// + IEnumerator IEnumerable.GetEnumerator() { - return ((IEnumerable)Collection).GetEnumerator(); + return ((IEnumerable)Collection).GetEnumerator(); } + /// + /// Gets the common tables associated with this clause. + /// + public IEnumerable GetCommonTables() + { + yield break; + } + + /// + /// Gets the internal queries associated with this clause. + /// public IEnumerable GetInternalQueries() { yield break; } + /// + /// Gets the parameters associated with this clause. + /// public IEnumerable GetParameters() { yield break; } + /// + /// Gets the physical tables associated with this clause. + /// public IEnumerable GetPhysicalTables() { yield break; } + /// + /// Gets the tokens representing this clause. + /// public IEnumerable GetTokens(Token? parent) { if (!Collection.Any()) yield break; @@ -70,28 +120,36 @@ public IEnumerable GetTokens(Token? parent) } } + /// + /// Searches for the specified comment and returns the zero-based index of the first occurrence within the entire collection. + /// public int IndexOf(string item) { return ((IList)Collection).IndexOf(item); } + /// + /// Inserts a comment into the collection at the specified index. + /// public void Insert(int index, string item) { ((IList)Collection).Insert(index, item); } + /// + /// Removes the first occurrence of a specific comment from the collection. + /// public bool Remove(string item) { return ((ICollection)Collection).Remove(item); } + /// + /// Removes the comment at the specified index. + /// public void RemoveAt(int index) { ((IList)Collection).RemoveAt(index); } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)Collection).GetEnumerator(); - } } + diff --git a/src/Carbunql/Clauses/CommonTable.cs b/src/Carbunql/Clauses/CommonTable.cs index d37541fe..d1608b33 100644 --- a/src/Carbunql/Clauses/CommonTable.cs +++ b/src/Carbunql/Clauses/CommonTable.cs @@ -5,19 +5,34 @@ namespace Carbunql.Clauses; +/// +/// Represents a common table expression (CTE) in SQL. +/// [MessagePackObject(keyAsPropertyName: true)] public class CommonTable : SelectableTable { + /// + /// Initializes a new instance of the class with the specified table and alias. + /// public CommonTable(TableBase table, string alias) : base(table, alias) { } + /// + /// Initializes a new instance of the class with the specified table, alias, and column aliases. + /// public CommonTable(TableBase table, string alias, ValueCollection columnAliases) : base(table, alias, columnAliases) { } + /// + /// Gets or sets the materialization type of the common table expression. + /// public Materialized Materialized { get; set; } = Materialized.Undefined; + /// + /// Gets the tokens representing this common table expression. + /// public override IEnumerable GetTokens(Token? parent) { foreach (var item in GetAliasTokens(parent)) yield return item; @@ -31,10 +46,19 @@ public override IEnumerable GetTokens(Token? parent) foreach (var item in Table.GetTokens(parent)) yield return item; } + /// + /// Gets a value indicating whether this common table expression is based on a SELECT query. + /// public bool IsSelectQuery => Table.IsSelectQuery; + /// + /// Gets the underlying SELECT query if this common table expression is based on a SELECT query. + /// public SelectQuery GetSelectQuery() => Table.GetSelectQuery(); + /// + /// Gets the common table expressions associated with this common table. + /// public override IEnumerable GetCommonTables() { if (Table is VirtualTable v) @@ -47,4 +71,4 @@ public override IEnumerable GetCommonTables() yield return this; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/DeleteClause.cs b/src/Carbunql/Clauses/DeleteClause.cs index 44cb3b1a..0d422be0 100644 --- a/src/Carbunql/Clauses/DeleteClause.cs +++ b/src/Carbunql/Clauses/DeleteClause.cs @@ -2,15 +2,27 @@ namespace Carbunql.Clauses; +/// +/// Represents a DELETE statement in SQL. +/// public class DeleteClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified table. + /// public DeleteClause(SelectableTable table) { Table = new SelectableTable(table.Table, table.Alias); } + /// + /// Gets the table from which rows will be deleted. + /// public SelectableTable Table { get; init; } + /// + /// Gets the tokens representing this DELETE statement. + /// public IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "delete from"); @@ -18,6 +30,9 @@ public IEnumerable GetTokens(Token? parent) foreach (var item in Table.GetTokens(t)) yield return item; } + /// + /// Gets the internal queries associated with this DELETE statement. + /// public IEnumerable GetInternalQueries() { foreach (var item in Table.GetInternalQueries()) @@ -26,6 +41,9 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the physical tables associated with this DELETE statement. + /// public IEnumerable GetPhysicalTables() { foreach (var item in Table.GetPhysicalTables()) @@ -34,11 +52,17 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Gets the parameters associated with this DELETE statement. + /// public IEnumerable GetParameters() { return Table.GetParameters(); } + /// + /// Gets the common tables associated with this DELETE statement. + /// public IEnumerable GetCommonTables() { foreach (var item in Table.GetCommonTables()) @@ -46,4 +70,4 @@ public IEnumerable GetCommonTables() yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/DistinctClause.cs b/src/Carbunql/Clauses/DistinctClause.cs index 3213d2bf..9567f883 100644 --- a/src/Carbunql/Clauses/DistinctClause.cs +++ b/src/Carbunql/Clauses/DistinctClause.cs @@ -4,23 +4,37 @@ namespace Carbunql.Clauses; +/// +/// Represents a DISTINCT clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class DistinctClause : IList, IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public DistinctClause() { Items = new(); } + /// + /// Initializes a new instance of the class with the specified items. + /// public DistinctClause(IList items) { Items = new(); Items.AddRange(items); } + /// + /// Gets the items in the DISTINCT clause. + /// private List Items { get; init; } - + /// + /// Gets the internal queries associated with this DISTINCT clause. + /// public IEnumerable GetInternalQueries() { foreach (var value in Items) @@ -32,6 +46,9 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the physical tables associated with this DISTINCT clause. + /// public IEnumerable GetPhysicalTables() { foreach (var value in Items) @@ -43,6 +60,9 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Gets the common tables associated with this DISTINCT clause. + /// public IEnumerable GetCommonTables() { foreach (var value in Items) @@ -54,6 +74,9 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the tokens representing this DISTINCT clause. + /// public IEnumerable GetTokens(Token? parent) { var clause = Token.Reserved(this, parent, "distinct"); @@ -85,6 +108,9 @@ public IEnumerable GetTokens(Token? parent) } } + /// + /// Gets the parameters associated with this DISTINCT clause. + /// public IEnumerable GetParameters() { foreach (var item in Items) diff --git a/src/Carbunql/Clauses/FromClause.cs b/src/Carbunql/Clauses/FromClause.cs index a91c088b..cf44742b 100644 --- a/src/Carbunql/Clauses/FromClause.cs +++ b/src/Carbunql/Clauses/FromClause.cs @@ -3,18 +3,33 @@ namespace Carbunql.Clauses; +/// +/// Represents a FROM clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class FromClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified root selectable table. + /// public FromClause(SelectableTable root) { Root = root; } + /// + /// Gets or sets the root selectable table in the FROM clause. + /// public SelectableTable Root { get; init; } + /// + /// Gets or sets the list of relations in the FROM clause. + /// public List? Relations { get; set; } + /// + /// Gets the internal queries associated with this FROM clause. + /// public IEnumerable GetInternalQueries() { foreach (var item in Root.GetInternalQueries()) @@ -34,6 +49,9 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the physical tables associated with this FROM clause. + /// public IEnumerable GetPhysicalTables() { foreach (var item in Root.GetPhysicalTables()) @@ -53,6 +71,9 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Gets the selectable tables associated with this FROM clause. + /// public IEnumerable GetSelectableTables() { yield return Root; @@ -66,6 +87,9 @@ public IEnumerable GetSelectableTables() } } + /// + /// Gets the common tables associated with this FROM clause. + /// public IEnumerable GetCommonTables() { foreach (var item in Root.GetCommonTables()) @@ -85,6 +109,9 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the parameters associated with this FROM clause. + /// public IEnumerable GetParameters() { foreach (var item in Root.GetParameters()) @@ -103,6 +130,9 @@ public IEnumerable GetParameters() } } + /// + /// Gets the tokens representing this FROM clause. + /// public IEnumerable GetTokens(Token? parent) { var clause = Token.Reserved(this, parent, "from"); @@ -117,4 +147,4 @@ public IEnumerable GetTokens(Token? parent) foreach (var token in item.GetTokens(clause)) yield return token; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/GroupClause.cs b/src/Carbunql/Clauses/GroupClause.cs index 3dc142bc..94353683 100644 --- a/src/Carbunql/Clauses/GroupClause.cs +++ b/src/Carbunql/Clauses/GroupClause.cs @@ -4,14 +4,23 @@ namespace Carbunql.Clauses; +/// +/// Represents a GROUP BY clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class GroupClause : IList, IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public GroupClause() { Items = new(); } + /// + /// Initializes a new instance of the class with the specified list of items. + /// public GroupClause(IList items) { Items = new(); @@ -20,6 +29,9 @@ public GroupClause(IList items) private List Items { get; init; } + /// + /// Gets the internal queries associated with this GROUP BY clause. + /// public IEnumerable GetInternalQueries() { foreach (var value in Items) @@ -31,6 +43,9 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the physical tables associated with this GROUP BY clause. + /// public IEnumerable GetPhysicalTables() { foreach (var value in Items) @@ -42,6 +57,9 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Gets the common tables associated with this GROUP BY clause. + /// public IEnumerable GetCommonTables() { foreach (var value in Items) @@ -53,6 +71,9 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the tokens representing this GROUP BY clause. + /// public IEnumerable GetTokens(Token? parent) { var clause = Token.Reserved(this, parent, "group by"); @@ -73,6 +94,9 @@ public IEnumerable GetTokens(Token? parent) } } + /// + /// Gets the parameters associated with this GROUP BY clause. + /// public IEnumerable GetParameters() { foreach (var item in Items) diff --git a/src/Carbunql/Clauses/HavingClause.cs b/src/Carbunql/Clauses/HavingClause.cs index 8de146e3..01ea9bcd 100644 --- a/src/Carbunql/Clauses/HavingClause.cs +++ b/src/Carbunql/Clauses/HavingClause.cs @@ -3,16 +3,29 @@ namespace Carbunql.Clauses; +/// +/// Represents a HAVING clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class HavingClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified condition. + /// + /// The condition of the HAVING clause. public HavingClause(ValueBase condition) { Condition = condition; } + /// + /// Gets the condition of the HAVING clause. + /// public ValueBase Condition { get; init; } + /// + /// Gets the internal queries associated with this HAVING clause. + /// public IEnumerable GetInternalQueries() { foreach (var item in Condition.GetInternalQueries()) @@ -21,6 +34,9 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the physical tables associated with this HAVING clause. + /// public IEnumerable GetPhysicalTables() { foreach (var item in Condition.GetPhysicalTables()) @@ -29,6 +45,9 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Gets the common tables associated with this HAVING clause. + /// public IEnumerable GetCommonTables() { foreach (var item in Condition.GetCommonTables()) @@ -37,11 +56,17 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the parameters associated with this HAVING clause. + /// public IEnumerable GetParameters() { return Condition.GetParameters(); } + /// + /// Gets the tokens representing this HAVING clause. + /// public IEnumerable GetTokens(Token? parent) { var clause = Token.Reserved(this, parent, "having"); @@ -49,4 +74,4 @@ public IEnumerable GetTokens(Token? parent) foreach (var item in Condition.GetTokens(clause)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/ISelectable.cs b/src/Carbunql/Clauses/ISelectable.cs index c69624ca..e4219c33 100644 --- a/src/Carbunql/Clauses/ISelectable.cs +++ b/src/Carbunql/Clauses/ISelectable.cs @@ -1,6 +1,12 @@ namespace Carbunql.Clauses; +/// +/// Represents an interface for selectable items in a SQL query. +/// public interface ISelectable { + /// + /// Gets the alias associated with the selectable item. + /// string Alias { get; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/InClause.cs b/src/Carbunql/Clauses/InClause.cs index c1f3f804..f9d652df 100644 --- a/src/Carbunql/Clauses/InClause.cs +++ b/src/Carbunql/Clauses/InClause.cs @@ -4,9 +4,15 @@ namespace Carbunql.Clauses; +/// +/// Represents an IN clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class InClause : ValueBase { + /// + /// Initializes a new instance of the class. + /// public InClause() { Value = null!; @@ -14,38 +20,49 @@ public InClause() IsNegative = false; } + /// + /// Initializes a new instance of the class with the specified value and argument. + /// + /// The value of the IN clause. + /// The argument of the IN clause. public InClause(ValueBase value, ValueBase argument) { Value = value; - if (argument is BracketValue || argument is QueryContainer) - { - Argument = argument; - } - else - { - Argument = new BracketValue(argument); - } + Argument = (argument is BracketValue || argument is QueryContainer) ? argument : new BracketValue(argument); IsNegative = false; } + /// + /// Initializes a new instance of the class with the specified value, argument, and negativity indicator. + /// + /// The value of the IN clause. + /// The argument of the IN clause. + /// Indicates whether the IN clause is negative. public InClause(ValueBase value, ValueBase argument, bool isNegative) { Value = value; - if (argument is BracketValue || argument is QueryContainer) - { - Argument = argument; - } - else - { - Argument = new BracketValue(argument); - } + Argument = (argument is BracketValue || argument is QueryContainer) ? argument : new BracketValue(argument); IsNegative = isNegative; } + /// + /// Gets the value of the IN clause. + /// public ValueBase Value { get; init; } + /// + /// Gets the argument of the IN clause. + /// public ValueBase Argument { get; init; } + /// + /// Indicates whether the IN clause is negative. + /// + public bool IsNegative { get; set; } + + /// + /// Gets the internal queries associated with this IN clause. + /// protected override IEnumerable GetInternalQueriesCore() { foreach (var item in Value.GetInternalQueries()) @@ -58,8 +75,9 @@ protected override IEnumerable GetInternalQueriesCore() } } - public bool IsNegative { get; set; } - + /// + /// Gets the tokens representing this IN clause. + /// public override IEnumerable GetCurrentTokens(Token? parent) { foreach (var item in Value.GetTokens(parent)) yield return item; @@ -70,6 +88,9 @@ public override IEnumerable GetCurrentTokens(Token? parent) foreach (var item in Argument.GetTokens(parent)) yield return item; } + /// + /// Gets the parameters associated with this IN clause. + /// protected override IEnumerable GetParametersCore() { foreach (var item in Value.GetParameters()) @@ -82,6 +103,9 @@ protected override IEnumerable GetParametersCore() } } + /// + /// Gets the physical tables associated with this IN clause. + /// protected override IEnumerable GetPhysicalTablesCore() { foreach (var item in Value.GetPhysicalTables()) @@ -94,6 +118,9 @@ protected override IEnumerable GetPhysicalTablesCore() } } + /// + /// Gets the common tables associated with this IN clause. + /// protected override IEnumerable GetCommonTablesCore() { foreach (var item in Value.GetCommonTables()) @@ -105,4 +132,4 @@ protected override IEnumerable GetCommonTablesCore() yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/IndexOnClause.cs b/src/Carbunql/Clauses/IndexOnClause.cs index a77f1e54..bdb78197 100644 --- a/src/Carbunql/Clauses/IndexOnClause.cs +++ b/src/Carbunql/Clauses/IndexOnClause.cs @@ -3,35 +3,60 @@ namespace Carbunql.Clauses; +/// +/// Represents an INDEX ON clause in a SQL query. +/// public class IndexOnClause : QueryCommandCollection, ITable { + /// + /// Initializes a new instance of the class with the specified table name. + /// + /// The name of the table. public IndexOnClause(string table) { Schema = string.Empty; Table = table; } + /// + /// Initializes a new instance of the class with the specified schema and table names. + /// + /// The name of the schema. + /// The name of the table. public IndexOnClause(string schema, string table) { Schema = schema; Table = table; } + /// + /// Initializes a new instance of the class with the specified table. + /// + /// The table. public IndexOnClause(ITable t) { Schema = t.Schema; Table = t.Table; - } + /// + /// Gets or sets the schema name. + /// public string Schema { get; init; } + /// + /// Gets or sets the table name. + /// public string Table { get; init; } - //public string TableFullName => (string.IsNullOrEmpty(Schema)) ? Table : Schema + "." + Table; - + /// + /// Gets or sets the USING clause. + /// public string? Using { get; set; } = null; + /// + /// Gets the tokens representing this INDEX ON clause. + /// public override IEnumerable GetTokens(Token? parent) { if (!Items.Any()) yield break; @@ -51,24 +76,35 @@ public override IEnumerable GetTokens(Token? parent) yield return Token.ReservedBracketEnd(this, parent); } + /// + /// Gets the internal queries associated with this INDEX ON clause. + /// public IEnumerable GetInternalQueries() { yield break; } + /// + /// Gets the physical tables associated with this INDEX ON clause. + /// public IEnumerable GetPhysicalTables() { yield break; } + /// + /// Gets the common tables associated with this INDEX ON clause. + /// public IEnumerable GetCommonTables() { yield break; } - + /// + /// Gets the parameters associated with this INDEX ON clause. + /// public override IEnumerable GetParameters() { yield break; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/InsertClause.cs b/src/Carbunql/Clauses/InsertClause.cs index 2e2fe807..b907ac80 100644 --- a/src/Carbunql/Clauses/InsertClause.cs +++ b/src/Carbunql/Clauses/InsertClause.cs @@ -3,17 +3,33 @@ namespace Carbunql.Clauses; +/// +/// Represents an INSERT INTO clause in a SQL query. +/// public class InsertClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified physical table. + /// + /// The physical table to insert into. public InsertClause(PhysicalTable table) { Table = table; } + /// + /// Gets or sets the physical table to insert into. + /// public PhysicalTable Table { get; init; } + /// + /// Gets or sets the column aliases for the INSERT INTO clause. + /// public ValueCollection? ColumnAliases { get; init; } + /// + /// Gets the common tables associated with this INSERT INTO clause. + /// public IEnumerable GetCommonTables() { foreach (var item in Table.GetCommonTables()) @@ -22,6 +38,9 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the internal queries associated with this INSERT INTO clause. + /// public IEnumerable GetInternalQueries() { foreach (var item in Table.GetInternalQueries()) @@ -30,11 +49,17 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the parameters associated with this INSERT INTO clause. + /// public IEnumerable GetParameters() { return Table.GetParameters(); } + /// + /// Gets the physical tables associated with this INSERT INTO clause. + /// public IEnumerable GetPhysicalTables() { foreach (var item in Table.GetPhysicalTables()) @@ -43,6 +68,9 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Gets the tokens representing this INSERT INTO clause. + /// public IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "insert into"); @@ -57,4 +85,4 @@ public IEnumerable GetTokens(Token? parent) yield return Token.ReservedBracketEnd(this, t); } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/LimitClause.cs b/src/Carbunql/Clauses/LimitClause.cs index 87ba019c..2ce261fb 100644 --- a/src/Carbunql/Clauses/LimitClause.cs +++ b/src/Carbunql/Clauses/LimitClause.cs @@ -4,24 +4,42 @@ namespace Carbunql.Clauses; +/// +/// Represents a clause for limiting the number of rows returned in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class LimitClause : IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public LimitClause() { Condition = null!; } + /// + /// Initializes a new instance of the class with the specified text condition. + /// + /// The text condition for limiting the rows. public LimitClause(string text) { Condition = new LiteralValue(text); } + /// + /// Initializes a new instance of the class with the specified value condition. + /// + /// The value condition for limiting the rows. public LimitClause(ValueBase item) { Condition = item; } + /// + /// Initializes a new instance of the class with the specified list of conditions. + /// + /// The list of conditions for limiting the rows. public LimitClause(List conditions) { var lst = new ValueCollection(); @@ -29,10 +47,17 @@ public LimitClause(List conditions) Condition = lst; } + /// + /// Gets or sets the condition for limiting the rows. + /// public ValueBase Condition { get; init; } + /// + /// Gets or sets the offset value for skipping rows before starting to return the result set. + /// public ValueBase? Offset { get; set; } + /// public IEnumerable GetInternalQueries() { foreach (var item in Condition.GetInternalQueries()) @@ -48,6 +73,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in Condition.GetPhysicalTables()) @@ -63,7 +89,7 @@ public IEnumerable GetPhysicalTables() } } - + /// public IEnumerable GetCommonTables() { foreach (var item in Condition.GetCommonTables()) @@ -79,6 +105,7 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetParameters() { foreach (var item in Condition.GetParameters()) @@ -95,6 +122,7 @@ public IEnumerable GetParameters() } } + /// public IEnumerable GetTokens(Token? parent) { var clause = Token.Reserved(this, parent, "limit"); @@ -107,4 +135,4 @@ public IEnumerable GetTokens(Token? parent) foreach (var item in Offset.GetTokens(clause)) yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeClause.cs b/src/Carbunql/Clauses/MergeClause.cs index 0ecfbb56..3b8e434f 100644 --- a/src/Carbunql/Clauses/MergeClause.cs +++ b/src/Carbunql/Clauses/MergeClause.cs @@ -2,20 +2,32 @@ namespace Carbunql.Clauses; +/// +/// Represents a clause for merging data into a table in a SQL query. +/// public class MergeClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified selectable table. + /// + /// The selectable table. public MergeClause(SelectableTable table) { Table = table; } + /// + /// Gets the selectable table involved in the merge operation. + /// public SelectableTable Table { get; init; } + /// public IEnumerable GetParameters() { return Table.GetParameters(); } + /// public IEnumerable GetInternalQueries() { foreach (var item in Table.GetInternalQueries()) @@ -24,6 +36,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in Table.GetPhysicalTables()) @@ -32,6 +45,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { foreach (var item in Table.GetCommonTables()) @@ -40,10 +54,11 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "merge into"); yield return t; foreach (var item in Table.GetTokens(t)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeCondition.cs b/src/Carbunql/Clauses/MergeCondition.cs index 73720873..a4c3dc0b 100644 --- a/src/Carbunql/Clauses/MergeCondition.cs +++ b/src/Carbunql/Clauses/MergeCondition.cs @@ -2,10 +2,21 @@ namespace Carbunql.Clauses; +/// +/// Represents an abstract class for merge conditions in a SQL query. +/// public abstract class MergeCondition : IQueryCommandable { + /// + /// Gets or sets the condition for the merge operation. + /// public ValueBase? Condition { get; set; } + /// + /// Gets the tokens representing the merge condition. + /// + /// The parent token. + /// The tokens representing the merge condition. public IEnumerable GetConditionTokens(Token? parent) { if (Condition == null) yield break; @@ -13,6 +24,7 @@ public IEnumerable GetConditionTokens(Token? parent) foreach (var item in Condition.GetTokens(parent)) yield return item; } + /// public IEnumerable GetInternalQueries() { if (Condition != null) @@ -24,6 +36,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { if (Condition != null) @@ -35,6 +48,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { if (Condition != null) @@ -46,7 +60,16 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the parameters associated with the merge condition. + /// + /// The parameters associated with the merge condition. public abstract IEnumerable GetParameters(); + /// + /// Gets the tokens representing the merge condition. + /// + /// The parent token. + /// The tokens representing the merge condition. public abstract IEnumerable GetTokens(Token? parent); -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeInsertClause.cs b/src/Carbunql/Clauses/MergeInsertClause.cs index eeeab19d..eef24c34 100644 --- a/src/Carbunql/Clauses/MergeInsertClause.cs +++ b/src/Carbunql/Clauses/MergeInsertClause.cs @@ -3,15 +3,26 @@ namespace Carbunql.Clauses; +/// +/// Represents a clause for the "INSERT" part of a "MERGE" SQL statement. +/// public class MergeInsertClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified column aliases. + /// + /// The column aliases. public MergeInsertClause(ValueCollection columnAliases) { ColumnAliases = columnAliases; } + /// + /// Gets the column aliases. + /// public ValueCollection ColumnAliases { get; init; } + /// public virtual IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "insert"); @@ -22,11 +33,13 @@ public virtual IEnumerable GetTokens(Token? parent) yield return Token.ReservedBracketEnd(this, parent); } + /// public virtual IEnumerable GetParameters() { return ColumnAliases.GetParameters(); } + /// public IEnumerable GetInternalQueries() { foreach (var item in ColumnAliases.GetInternalQueries()) @@ -35,6 +48,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in ColumnAliases.GetPhysicalTables()) @@ -43,6 +57,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { foreach (var item in ColumnAliases.GetCommonTables()) @@ -50,4 +65,4 @@ public IEnumerable GetCommonTables() yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeSetClause.cs b/src/Carbunql/Clauses/MergeSetClause.cs index 2b698466..39d5474a 100644 --- a/src/Carbunql/Clauses/MergeSetClause.cs +++ b/src/Carbunql/Clauses/MergeSetClause.cs @@ -2,8 +2,12 @@ namespace Carbunql.Clauses; +/// +/// Represents a clause for the "SET" part of a "MERGE" SQL statement. +/// public class MergeSetClause : QueryCommandCollection, IQueryCommandable { + /// public IEnumerable GetCommonTables() { foreach (var value in Items) @@ -15,6 +19,7 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetInternalQueries() { foreach (var value in Items) @@ -26,6 +31,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var value in Items) @@ -37,8 +43,9 @@ public IEnumerable GetPhysicalTables() } } + /// public override IEnumerable GetTokens(Token? parent) { foreach (var item in base.GetTokens(parent)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeWhenDelete.cs b/src/Carbunql/Clauses/MergeWhenDelete.cs index ad3ac426..44688d12 100644 --- a/src/Carbunql/Clauses/MergeWhenDelete.cs +++ b/src/Carbunql/Clauses/MergeWhenDelete.cs @@ -1,11 +1,16 @@ namespace Carbunql.Clauses; +/// +/// Represents a "WHEN MATCHED THEN DELETE" condition in a "MERGE" SQL statement. +/// public class MergeWhenDelete : MergeCondition { + /// public MergeWhenDelete() { } + /// public override IEnumerable GetParameters() { if (Condition != null) @@ -17,6 +22,7 @@ public override IEnumerable GetParameters() } } + /// public override IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "when matched"); @@ -25,4 +31,4 @@ public override IEnumerable GetTokens(Token? parent) yield return Token.Reserved(this, parent, "then"); yield return Token.Reserved(this, parent, "delete"); } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeWhenInsert.cs b/src/Carbunql/Clauses/MergeWhenInsert.cs index 9955d759..9fba1e48 100644 --- a/src/Carbunql/Clauses/MergeWhenInsert.cs +++ b/src/Carbunql/Clauses/MergeWhenInsert.cs @@ -1,14 +1,25 @@ namespace Carbunql.Clauses; +/// +/// Represents a "WHEN NOT MATCHED THEN INSERT" condition in a "MERGE" SQL statement. +/// public class MergeWhenInsert : MergeCondition { + /// + /// Initializes a new instance of the class with the specified . + /// + /// The to be executed when the condition is met. public MergeWhenInsert(MergeInsertQuery query) { Query = query; } + /// + /// Gets the to be executed when the condition is met. + /// public MergeInsertQuery Query { get; init; } + /// public override IEnumerable GetParameters() { foreach (var item in Query.GetParameters()) @@ -24,6 +35,7 @@ public override IEnumerable GetParameters() } } + /// public override IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "when not matched"); @@ -32,4 +44,4 @@ public override IEnumerable GetTokens(Token? parent) yield return Token.Reserved(this, parent, "then"); foreach (var item in Query.GetTokens(t)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeWhenNothing.cs b/src/Carbunql/Clauses/MergeWhenNothing.cs index 4d94e9ac..3bb439d3 100644 --- a/src/Carbunql/Clauses/MergeWhenNothing.cs +++ b/src/Carbunql/Clauses/MergeWhenNothing.cs @@ -1,13 +1,23 @@ namespace Carbunql.Clauses; +/// +/// Represents a "WHEN MATCHED THEN DO NOTHING" or "WHEN NOT MATCHED THEN DO NOTHING" condition in a "MERGE" SQL statement. +/// public class MergeWhenNothing : MergeCondition { + /// + /// Initializes a new instance of the class. + /// public MergeWhenNothing() { } + /// + /// Gets or sets a value indicating whether this condition is a match condition. + /// public bool IsMatchCondition { get; set; } + /// public override IEnumerable GetParameters() { if (Condition != null) @@ -19,6 +29,7 @@ public override IEnumerable GetParameters() } } + /// public override IEnumerable GetTokens(Token? parent) { var txt = (IsMatchCondition) ? "when matched" : "when not matched"; @@ -28,4 +39,4 @@ public override IEnumerable GetTokens(Token? parent) yield return Token.Reserved(this, parent, "then"); yield return Token.Reserved(this, parent, "do nothing"); } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/MergeWhenUpdate.cs b/src/Carbunql/Clauses/MergeWhenUpdate.cs index de8a604f..60ab80e8 100644 --- a/src/Carbunql/Clauses/MergeWhenUpdate.cs +++ b/src/Carbunql/Clauses/MergeWhenUpdate.cs @@ -1,14 +1,25 @@ namespace Carbunql.Clauses; +/// +/// Represents a "WHEN MATCHED THEN UPDATE" condition in a "MERGE" SQL statement. +/// public class MergeWhenUpdate : MergeCondition { + /// + /// Initializes a new instance of the class. + /// + /// The update query. public MergeWhenUpdate(MergeUpdateQuery query) { Query = query; } + /// + /// Gets the update query. + /// public MergeUpdateQuery Query { get; init; } + /// public override IEnumerable GetParameters() { foreach (var item in Query.GetParameters()) @@ -24,6 +35,7 @@ public override IEnumerable GetParameters() } } + /// public override IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "when matched"); @@ -32,4 +44,4 @@ public override IEnumerable GetTokens(Token? parent) yield return Token.Reserved(this, parent, "then"); foreach (var item in Query.GetTokens(t)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/NamedWindowDefinition.cs b/src/Carbunql/Clauses/NamedWindowDefinition.cs index 649c0b6e..089f434d 100644 --- a/src/Carbunql/Clauses/NamedWindowDefinition.cs +++ b/src/Carbunql/Clauses/NamedWindowDefinition.cs @@ -3,57 +3,84 @@ namespace Carbunql.Clauses; +/// +/// Represents a named window definition in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class NamedWindowDefinition : IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public NamedWindowDefinition() { Alias = null!; WindowDefinition = null!; } + /// + /// Initializes a new instance of the class with the specified alias. + /// + /// The alias for the named window. public NamedWindowDefinition(string alias) { Alias = alias; WindowDefinition = null!; } + /// + /// Initializes a new instance of the class with the specified alias and window definition. + /// + /// The alias for the named window. + /// The window definition. public NamedWindowDefinition(string alias, WindowDefinition definition) { Alias = alias; WindowDefinition = definition; } + /// + /// Gets or sets the alias for the named window. + /// public string Alias { get; set; } + /// + /// Gets or sets the window definition. + /// public WindowDefinition WindowDefinition { get; set; } + /// public IEnumerable GetInternalQueries() { foreach (var item in WindowDefinition.GetInternalQueries()) yield return item; } + /// public IEnumerable GetParameters() { return WindowDefinition.GetParameters(); } + /// public IEnumerable GetPhysicalTables() { foreach (var item in WindowDefinition.GetPhysicalTables()) yield return item; } + /// public IEnumerable GetCommonTables() { foreach (var item in WindowDefinition.GetCommonTables()) yield return item; } + /// public IEnumerable GetTokens(Token? parent) { - yield return new Token(this, parent, Alias); ; + yield return new Token(this, parent, Alias); yield return Token.Reserved(this, parent, "as"); foreach (var item in WindowDefinition.GetTokens(parent)) yield return item; } } + diff --git a/src/Carbunql/Clauses/OrderClause.cs b/src/Carbunql/Clauses/OrderClause.cs index 171859f1..f3270262 100644 --- a/src/Carbunql/Clauses/OrderClause.cs +++ b/src/Carbunql/Clauses/OrderClause.cs @@ -3,17 +3,28 @@ namespace Carbunql.Clauses; +/// +/// Represents an order clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class OrderClause : QueryCommandCollection, IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public OrderClause() : base() { } + /// + /// Initializes a new instance of the class with the specified collection. + /// + /// The collection of order items. public OrderClause(List collection) : base(collection) { } + /// public IEnumerable GetInternalQueries() { foreach (var value in Items) @@ -25,6 +36,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var value in Items) @@ -36,6 +48,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { foreach (var value in Items) @@ -47,6 +60,7 @@ public IEnumerable GetCommonTables() } } + /// public override IEnumerable GetTokens(Token? parent) { if (!Items.Any()) yield break; @@ -56,4 +70,4 @@ public override IEnumerable GetTokens(Token? parent) foreach (var item in base.GetTokens(clause)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/OverClause.cs b/src/Carbunql/Clauses/OverClause.cs index 4f7bed83..2a6fb3cc 100644 --- a/src/Carbunql/Clauses/OverClause.cs +++ b/src/Carbunql/Clauses/OverClause.cs @@ -3,26 +3,44 @@ namespace Carbunql.Clauses; +/// +/// Represents an OVER clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class OverClause : IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public OverClause() { WindowDefinition = null!; } + /// + /// Initializes a new instance of the class with the specified window definition. + /// + /// The window definition. public OverClause(WindowDefinition definition) { WindowDefinition = definition; } + /// + /// Initializes a new instance of the class with the specified named window definition. + /// + /// The named window definition. public OverClause(NamedWindowDefinition definition) { WindowDefinition = new WindowDefinition(definition.Alias); } + /// + /// Gets or sets the window definition associated with the OVER clause. + /// public WindowDefinition WindowDefinition { get; set; } + /// public IEnumerable GetCommonTables() { foreach (var item in WindowDefinition.GetCommonTables()) @@ -31,6 +49,7 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetInternalQueries() { foreach (var item in WindowDefinition.GetInternalQueries()) @@ -39,6 +58,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in WindowDefinition.GetPhysicalTables()) @@ -47,11 +67,13 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetParameters() { return WindowDefinition.GetParameters(); } + /// public IEnumerable GetTokens(Token? parent) { var overToken = Token.Reserved(this, parent, "over"); @@ -59,4 +81,4 @@ public IEnumerable GetTokens(Token? parent) foreach (var item in WindowDefinition.GetTokens(overToken)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/PartitionClause.cs b/src/Carbunql/Clauses/PartitionClause.cs index e1a644af..a0556fc0 100644 --- a/src/Carbunql/Clauses/PartitionClause.cs +++ b/src/Carbunql/Clauses/PartitionClause.cs @@ -3,17 +3,28 @@ namespace Carbunql.Clauses; +/// +/// Represents a PARTITION BY clause in a SQL query. +/// [MessagePackObject(keyAsPropertyName: true)] public class PartitionClause : QueryCommandCollection, IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public PartitionClause() : base() { } + /// + /// Initializes a new instance of the class with the specified collection of values. + /// + /// The collection of values. public PartitionClause(List collection) : base(collection) { } + /// public IEnumerable GetInternalQueries() { foreach (var value in Items) @@ -25,6 +36,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var value in Items) @@ -36,6 +48,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { foreach (var value in Items) @@ -47,6 +60,7 @@ public IEnumerable GetCommonTables() } } + /// public override IEnumerable GetTokens(Token? parent) { if (!Items.Any()) yield break; @@ -56,4 +70,4 @@ public override IEnumerable GetTokens(Token? parent) foreach (var item in base.GetTokens(clause)) yield return item; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/QueryCommandCollection.cs b/src/Carbunql/Clauses/QueryCommandCollection.cs index fa63b8ee..132381e2 100644 --- a/src/Carbunql/Clauses/QueryCommandCollection.cs +++ b/src/Carbunql/Clauses/QueryCommandCollection.cs @@ -3,18 +3,35 @@ namespace Carbunql.Clauses; +/// +/// Represents a collection of query commandable items. +/// +/// The type of items in the collection, which must implement . [MessagePackObject(keyAsPropertyName: true)] public abstract class QueryCommandCollection : IList where T : IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public QueryCommandCollection() { } + /// + /// Initializes a new instance of the class with the specified collection of items. + /// + /// The collection of items. public QueryCommandCollection(List collection) { Items.AddRange(collection); } + /// + /// Gets or sets the list of items in the collection. + /// + protected List Items { get; set; } = new(); + + /// public virtual IEnumerable GetTokens(Token? parent) { if (!Items.Any()) yield break; @@ -34,6 +51,7 @@ public virtual IEnumerable GetTokens(Token? parent) } } + /// public virtual IEnumerable GetParameters() { foreach (var item in Items) @@ -45,8 +63,6 @@ public virtual IEnumerable GetParameters() } } - public List Items { get; set; } = new(); - #region implements IList [IgnoreMember] public T this[int index] { get => ((IList)Items)[index]; set => ((IList)Items)[index] = value; } diff --git a/src/Carbunql/Clauses/Relation.cs b/src/Carbunql/Clauses/Relation.cs index 7af75eaa..bd1c6032 100644 --- a/src/Carbunql/Clauses/Relation.cs +++ b/src/Carbunql/Clauses/Relation.cs @@ -3,9 +3,15 @@ namespace Carbunql.Clauses; +/// +/// Represents a relation in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class Relation : IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public Relation() { JoinCommand = string.Empty; @@ -13,12 +19,23 @@ public Relation() Table = null!; } + /// + /// Initializes a new instance of the class with the specified query and join command. + /// + /// The selectable table. + /// The join command. public Relation(SelectableTable query, string joinCommand) { Table = query; JoinCommand = joinCommand; } + /// + /// Initializes a new instance of the class with the specified query, join command, and condition. + /// + /// The selectable table. + /// The join command. + /// The join condition. public Relation(SelectableTable query, string joinCommand, ValueBase condition) { Table = query; @@ -26,12 +43,22 @@ public Relation(SelectableTable query, string joinCommand, ValueBase condition) Condition = condition; } + /// + /// Gets or sets the join command. + /// public string JoinCommand { get; init; } + /// + /// Gets or sets the join condition. + /// public ValueBase? Condition { get; set; } + /// + /// Gets or sets the selectable table. + /// public SelectableTable Table { get; init; } + /// public IEnumerable GetInternalQueries() { foreach (var item in Table.GetInternalQueries()) @@ -47,6 +74,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in Table.GetPhysicalTables()) @@ -62,7 +90,7 @@ public IEnumerable GetPhysicalTables() } } - + /// public IEnumerable GetCommonTables() { foreach (var item in Table.GetCommonTables()) @@ -78,6 +106,7 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetParameters() { foreach (var item in Table.GetParameters()) @@ -93,6 +122,7 @@ public IEnumerable GetParameters() } } + /// public IEnumerable GetTokens(Token? parent) { yield return Token.Reserved(this, parent, JoinCommand); @@ -104,4 +134,4 @@ public IEnumerable GetTokens(Token? parent) foreach (var item in Condition.GetTokens(parent)) yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/ReturningClause.cs b/src/Carbunql/Clauses/ReturningClause.cs index ae3de11b..5607ec17 100644 --- a/src/Carbunql/Clauses/ReturningClause.cs +++ b/src/Carbunql/Clauses/ReturningClause.cs @@ -3,8 +3,15 @@ namespace Carbunql.Clauses; +/// +/// Represents a returning clause in a query. +/// public class ReturningClause : QueryCommandCollection, IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified value. + /// + /// The value to be returned. public ReturningClause(ValueBase value) { if (value is ValueCollection collection) @@ -20,6 +27,10 @@ public ReturningClause(ValueBase value) } } + /// + /// Initializes a new instance of the class with the specified values. + /// + /// The values to be returned. public ReturningClause(IEnumerable values) { foreach (var item in values) @@ -28,6 +39,7 @@ public ReturningClause(IEnumerable values) } } + /// public override IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "returning"); @@ -35,18 +47,21 @@ public override IEnumerable GetTokens(Token? parent) foreach (var item in base.GetTokens(t)) yield return item; } + /// public IEnumerable GetInternalQueries() { yield break; } + /// public IEnumerable GetPhysicalTables() { yield break; } + /// public IEnumerable GetCommonTables() { yield break; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/SelectClause.cs b/src/Carbunql/Clauses/SelectClause.cs index 4f6a00ce..6a8f72b9 100644 --- a/src/Carbunql/Clauses/SelectClause.cs +++ b/src/Carbunql/Clauses/SelectClause.cs @@ -3,13 +3,23 @@ namespace Carbunql.Clauses; +/// +/// Represents a SELECT clause in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class SelectClause : QueryCommandCollection, IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public SelectClause() { } + /// + /// Initializes a new instance of the class with the specified collection of selectable items. + /// + /// The collection of selectable items. public SelectClause(List collection) { Items.AddRange(collection); @@ -35,10 +45,17 @@ public bool HasDistinctKeyword } } + /// + /// Gets or sets the distinct clause of the select query. + /// public DistinctClause? Distinct { get; set; } + /// + /// Gets or sets the top clause of the select query. + /// public TopClause? Top { get; set; } + /// public IEnumerable GetInternalQueries() { if (Distinct != null) @@ -66,6 +83,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { if (Distinct != null) @@ -93,6 +111,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { if (Distinct != null) @@ -120,6 +139,7 @@ public IEnumerable GetCommonTables() } } + /// public override IEnumerable GetTokens(Token? parent) { var clause = Token.Reserved(this, parent, "select"); @@ -144,9 +164,13 @@ public override IEnumerable GetTokens(Token? parent) foreach (var item in base.GetTokens(clause)) yield return item; } + /// + /// Filters out the columns in the SELECT clause that are not present in the specified collection of columns. + /// + /// The collection of column names to filter in. public void FilterInColumns(IEnumerable columns) { var lst = this.Where(x => !columns.Contains(x.Alias)).ToList(); foreach (var item in lst) Remove(item); } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/SelectableItem.cs b/src/Carbunql/Clauses/SelectableItem.cs index d4258041..9e9040ea 100644 --- a/src/Carbunql/Clauses/SelectableItem.cs +++ b/src/Carbunql/Clauses/SelectableItem.cs @@ -3,29 +3,52 @@ namespace Carbunql.Clauses; +/// +/// Represents a selectable item in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class SelectableItem : IQueryCommandable, ISelectable { + /// + /// Initializes a new instance of the class with the specified value and alias. + /// + /// The value to be selected. + /// The alias for the selected value. public SelectableItem(ValueBase value, string alias) { Value = value; Alias = alias; } + /// + /// Gets or sets the value to be selected. + /// public ValueBase Value { get; private set; } + /// + /// Gets or sets the alias for the selected value. + /// public string Alias { get; private set; } + /// + /// Sets the value to be selected. + /// + /// The value to be selected. public void SetValue(ValueBase value) { Value = value; } + /// + /// Sets the alias for the selected value. + /// + /// The alias for the selected value. public void SetAlias(string alias) { Alias = alias; } + /// public IEnumerable GetInternalQueries() { foreach (var item in Value.GetInternalQueries()) @@ -34,6 +57,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in Value.GetPhysicalTables()) @@ -42,6 +66,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { foreach (var item in Value.GetCommonTables()) @@ -50,6 +75,7 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetTokens(Token? parent) { foreach (var item in Value.GetTokens(parent)) yield return item; @@ -60,8 +86,9 @@ public IEnumerable GetTokens(Token? parent) } } + /// public IEnumerable GetParameters() { return Value.GetParameters(); } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/SelectableTable.cs b/src/Carbunql/Clauses/SelectableTable.cs index 02935558..f6680fc5 100644 --- a/src/Carbunql/Clauses/SelectableTable.cs +++ b/src/Carbunql/Clauses/SelectableTable.cs @@ -4,15 +4,29 @@ namespace Carbunql.Clauses; +/// +/// Represents a selectable table in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class SelectableTable : IQueryCommandable, ISelectable { + /// + /// Initializes a new instance of the class with the specified table, alias, and column aliases. + /// + /// The table to be selected. + /// The alias for the selected table. public SelectableTable(TableBase table, string alias) { Table = table; Alias = alias; } + /// + /// Initializes a new instance of the class with the specified table, alias, and column aliases. + /// + /// The table to be selected. + /// The alias for the selected table. + /// The column aliases for the selected table. public SelectableTable(TableBase table, string alias, ValueCollection columnAliases) { Table = table; @@ -20,8 +34,14 @@ public SelectableTable(TableBase table, string alias, ValueCollection columnAlia ColumnAliases = columnAliases; } + /// + /// Gets the table to be selected. + /// public TableBase Table { get; init; } + /// + /// Gets or sets the alias for the selected table. + /// public string Alias { get; private set; } public void SetAlias(string alias) @@ -29,6 +49,9 @@ public void SetAlias(string alias) this.Alias = alias; } + /// + /// Gets or sets the column aliases for the selected table. + /// public ValueCollection? ColumnAliases { get; init; } public IEnumerable GetAliasTokens(Token? parent) @@ -47,6 +70,7 @@ public IEnumerable GetAliasTokens(Token? parent) } } + /// public virtual IEnumerable GetTokens(Token? parent) { foreach (var item in Table.GetTokens(parent)) yield return item; @@ -66,6 +90,7 @@ public virtual IEnumerable GetTokens(Token? parent) } } + /// public virtual IEnumerable GetParameters() { foreach (var item in Table.GetParameters()) @@ -88,6 +113,7 @@ public IEnumerable GetColumnNames() return Table.GetColumnNames(); } + /// public IEnumerable GetInternalQueries() { foreach (var item in Table.GetInternalQueries()) @@ -96,6 +122,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in Table.GetPhysicalTables()) @@ -104,6 +131,7 @@ public IEnumerable GetPhysicalTables() } } + /// public virtual IEnumerable GetCommonTables() { foreach (var item in Table.GetCommonTables()) @@ -111,4 +139,4 @@ public virtual IEnumerable GetCommonTables() yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/SetClause.cs b/src/Carbunql/Clauses/SetClause.cs index ddb0ba5d..e72c9157 100644 --- a/src/Carbunql/Clauses/SetClause.cs +++ b/src/Carbunql/Clauses/SetClause.cs @@ -2,8 +2,12 @@ namespace Carbunql.Clauses; +/// +/// Represents a SET clause in a query. +/// public class SetClause : QueryCommandCollection, IQueryCommandable { + /// public IEnumerable GetCommonTables() { foreach (var x in Items) @@ -15,6 +19,7 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetInternalQueries() { foreach (var x in Items) @@ -26,6 +31,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var x in Items) @@ -37,6 +43,7 @@ public IEnumerable GetPhysicalTables() } } + /// public override IEnumerable GetTokens(Token? parent) { Token clause = GetClauseToken(parent); @@ -49,4 +56,4 @@ private Token GetClauseToken(Token? parent) { return Token.Reserved(this, parent, "set"); } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/SortableItem.cs b/src/Carbunql/Clauses/SortableItem.cs index 11f23d67..0bd8cea7 100644 --- a/src/Carbunql/Clauses/SortableItem.cs +++ b/src/Carbunql/Clauses/SortableItem.cs @@ -4,9 +4,18 @@ namespace Carbunql.Clauses; +/// +/// Represents a sortable item used in ORDER BY clauses in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class SortableItem : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified value, sort order, and null sorting behavior. + /// + /// The value to sort. + /// Specifies whether the sorting is ascending (true) or descending (false). + /// Specifies the behavior for sorting null values. public SortableItem(ValueBase value, bool isAscending = true, NullSort nullSort = NullSort.Undefined) { Value = value; @@ -14,12 +23,22 @@ public SortableItem(ValueBase value, bool isAscending = true, NullSort nullSort NullSort = nullSort; } + /// + /// Gets the value to sort. + /// public ValueBase Value { get; init; } + /// + /// Gets or sets a value indicating whether the sorting is ascending (true) or descending (false). + /// public bool IsAscending { get; set; } = true; + /// + /// Gets or sets the behavior for sorting null values. + /// public NullSort NullSort { get; set; } = NullSort.Undefined; + /// public IEnumerable GetInternalQueries() { foreach (var item in Value.GetInternalQueries()) @@ -28,6 +47,7 @@ public IEnumerable GetInternalQueries() } } + /// public IEnumerable GetPhysicalTables() { foreach (var item in Value.GetPhysicalTables()) @@ -36,6 +56,7 @@ public IEnumerable GetPhysicalTables() } } + /// public IEnumerable GetCommonTables() { foreach (var item in Value.GetCommonTables()) @@ -44,15 +65,17 @@ public IEnumerable GetCommonTables() } } + /// public IEnumerable GetParameters() { return Value.GetParameters(); } + /// public IEnumerable GetTokens(Token? parent) { foreach (var item in Value.GetTokens(parent)) yield return item; if (!IsAscending) yield return Token.Reserved(this, parent, "desc"); if (NullSort != NullSort.Undefined) yield return Token.Reserved(this, parent, NullSort.ToCommandText()); } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/TableBase.cs b/src/Carbunql/Clauses/TableBase.cs index 63c8af26..df1c513d 100644 --- a/src/Carbunql/Clauses/TableBase.cs +++ b/src/Carbunql/Clauses/TableBase.cs @@ -7,6 +7,9 @@ namespace Carbunql.Clauses; +/// +/// Base class for various types of tables in a query. +/// [MessagePackObject(keyAsPropertyName: true)] [Union(0, typeof(FunctionTable))] [Union(1, typeof(PhysicalTable))] @@ -14,46 +17,108 @@ namespace Carbunql.Clauses; [Union(3, typeof(LateralTable))] public abstract class TableBase : IQueryCommandable { + /// + /// Gets the tokens representing this table in a query. + /// + /// The parent token. + /// The tokens representing this table. public abstract IEnumerable GetTokens(Token? parent); + /// + /// Gets the default name of the table. + /// + /// The default name of the table. public virtual string GetDefaultName() => string.Empty; + /// + /// Converts the table to a selectable table with the specified alias. + /// + /// The alias for the table. + /// A selectable table representing this table with the specified alias. public virtual SelectableTable ToSelectable() => ToSelectable(GetDefaultName()); + /// + /// Converts the table to a selectable table with the specified alias. + /// + /// The alias for the table. + /// A selectable table representing this table with the specified alias. public virtual SelectableTable ToSelectable(string alias) { return new SelectableTable(this, alias); } + /// + /// Converts the table to a selectable table with the specified alias and column aliases. + /// + /// The alias for the table. + /// The column aliases. + /// A selectable table representing this table with the specified alias and column aliases. public virtual SelectableTable ToSelectable(string alias, IEnumerable columnAliases) { return new SelectableTable(this, alias, columnAliases.ToValueCollection()); } + /// + /// Converts the table to a selectable table with the specified alias and column aliases. + /// + /// The alias for the table. + /// The column aliases. + /// A selectable table representing this table with the specified alias and column aliases. public virtual SelectableTable ToSelectable(string alias, ValueCollection columnAliases) { return new SelectableTable(this, alias, columnAliases); } + /// + /// Gets the parameters associated with this table. + /// + /// The parameters associated with this table. public virtual IEnumerable GetParameters() { yield break; } + /// + /// Gets the names of the columns in this table. + /// + /// The names of the columns in this table. public virtual IList GetColumnNames() { return ImmutableList.Empty; } + /// + /// Gets a value indicating whether this table is a select query. + /// public virtual bool IsSelectQuery => false; + /// + /// Gets the full name of the table. + /// + /// The full name of the table. public virtual string GetTableFullName() => ""; + /// + /// Gets the select query associated with this table. + /// + /// The select query associated with this table. public virtual SelectQuery GetSelectQuery() => throw new NotSupportedException(); + /// + /// Gets the internal queries associated with this table. + /// + /// The internal queries associated with this table. public abstract IEnumerable GetInternalQueries(); + /// + /// Gets the physical tables associated with this table. + /// + /// The physical tables associated with this table. public abstract IEnumerable GetPhysicalTables(); + /// + /// Gets the common tables associated with this table. + /// + /// The common tables associated with this table. public abstract IEnumerable GetCommonTables(); -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/TableDefinitionClause.cs b/src/Carbunql/Clauses/TableDefinitionClause.cs index d5f780dd..c8a680fd 100644 --- a/src/Carbunql/Clauses/TableDefinitionClause.cs +++ b/src/Carbunql/Clauses/TableDefinitionClause.cs @@ -3,24 +3,45 @@ namespace Carbunql.Clauses; +/// +/// Represents a collection of queries containing table definitions. +/// public class TableDefinitionClause : QueryCommandCollection, ITable { + /// + /// Gets or sets the schema name of the table. + /// + public string Schema { get; init; } + + /// + /// Gets or sets the table name. + /// + public string Table { get; init; } + + /// + /// Initializes a new instance of the class with a table instance. + /// + /// The table instance. public TableDefinitionClause(ITable t) { Schema = t.Schema; Table = t.Table; } + /// + /// Initializes a new instance of the class with the specified schema and table name. + /// + /// The schema name of the table. + /// The table name. public TableDefinitionClause(string schema, string table) { Schema = schema; Table = table; } - public string Schema { get; init; } - - public string Table { get; init; } - + /// + /// Gets the tokens of the collection. + /// public override IEnumerable GetTokens(Token? parent) { if (!Items.Any()) yield break; @@ -34,27 +55,41 @@ public override IEnumerable GetTokens(Token? parent) yield return Token.ReservedBracketEnd(this, parent); } + /// + /// Gets the internal queries. + /// public IEnumerable GetInternalQueries() { yield break; } + /// + /// Gets the physical tables. + /// public IEnumerable GetPhysicalTables() { yield break; } + /// + /// Gets the common tables. + /// public IEnumerable GetCommonTables() { yield break; } - + /// + /// Gets the parameters. + /// public override IEnumerable GetParameters() { yield break; } + /// + /// Gets the column names. + /// public IEnumerable GetColumnNames() { var lst = new List(); @@ -65,6 +100,9 @@ public IEnumerable GetColumnNames() return lst.Distinct(); } + /// + /// Normalizes the table. + /// public TableDefinitionClause ToNormalize() { var clause = new TableDefinitionClause(this); @@ -78,11 +116,14 @@ public TableDefinitionClause ToNormalize() return clause; } - public List Disasseble() + /// + /// Disassembles the table. + /// + public List Disassemble() { var lst = new List(); - //normalize unknown name primary key + // Normalize unknown name primary keys. var pkeys = Items.OfType().Where(x => x.IsPrimaryKey).Select(x => x.ColumnName).Distinct(); if (pkeys.Any()) { @@ -90,7 +131,7 @@ public List Disasseble() lst.Add(new AlterTableQuery(new AlterTableClause(this, c))); } - //normalize unknown name unique key + // Normalize unknown name unique keys. var ukeys = Items.OfType().Where(x => x.IsUniqueKey).Select(x => x.ColumnName).Distinct(); if (ukeys.Any()) { @@ -109,4 +150,4 @@ public List Disasseble() return lst; } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/TopClause.cs b/src/Carbunql/Clauses/TopClause.cs index 3333da30..6621550d 100644 --- a/src/Carbunql/Clauses/TopClause.cs +++ b/src/Carbunql/Clauses/TopClause.cs @@ -3,36 +3,63 @@ namespace Carbunql.Clauses; +using System.Collections.Generic; + +/// +/// Represents a clause for specifying the number of rows to be returned in a query result. +/// [MessagePackObject(keyAsPropertyName: true)] public class TopClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified value. + /// + /// The value representing the number of rows. public TopClause(ValueBase value) { Value = value; } + /// + /// Gets the value representing the number of rows. + /// public ValueBase Value { get; init; } + /// + /// Gets the common tables used in the clause. + /// public IEnumerable GetCommonTables() { return Value.GetCommonTables(); } + /// + /// Gets the internal queries used in the clause. + /// public IEnumerable GetInternalQueries() { return Value.GetInternalQueries(); } + /// + /// Gets the parameters used in the clause. + /// public IEnumerable GetParameters() { return Value.GetParameters(); } + /// + /// Gets the physical tables used in the clause. + /// public IEnumerable GetPhysicalTables() { return Value.GetPhysicalTables(); } + /// + /// Gets the tokens representing the clause. + /// public IEnumerable GetTokens(Token? parent) { yield return Token.Reserved(this, parent, "top"); diff --git a/src/Carbunql/Clauses/UpdateClause.cs b/src/Carbunql/Clauses/UpdateClause.cs index 92013353..9d346a4c 100644 --- a/src/Carbunql/Clauses/UpdateClause.cs +++ b/src/Carbunql/Clauses/UpdateClause.cs @@ -2,15 +2,28 @@ namespace Carbunql.Clauses; +/// +/// Represents a clause used to specify the table to be updated in an UPDATE statement. +/// public class UpdateClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified table. + /// + /// The table to be updated. public UpdateClause(SelectableTable table) { Table = new SelectableTable(table.Table, table.Alias); } + /// + /// Gets the table to be updated. + /// public SelectableTable Table { get; init; } + /// + /// Gets the tokens representing the UPDATE clause. + /// public IEnumerable GetTokens(Token? parent) { var t = Token.Reserved(this, parent, "update"); @@ -18,6 +31,9 @@ public IEnumerable GetTokens(Token? parent) foreach (var item in Table.GetTokens(t)) yield return item; } + /// + /// Gets the internal queries used in the clause. + /// public IEnumerable GetInternalQueries() { foreach (var item in Table.GetInternalQueries()) @@ -26,6 +42,9 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the physical tables used in the clause. + /// public IEnumerable GetPhysicalTables() { foreach (var item in Table.GetPhysicalTables()) @@ -34,6 +53,9 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Gets the common tables used in the clause. + /// public IEnumerable GetCommonTables() { foreach (var item in Table.GetCommonTables()) @@ -42,8 +64,12 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the parameters used in the clause. + /// + /// This method is not implemented and throws a . public IEnumerable GetParameters() { throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/UsingClause.cs b/src/Carbunql/Clauses/UsingClause.cs index 146b5d40..9736ca39 100644 --- a/src/Carbunql/Clauses/UsingClause.cs +++ b/src/Carbunql/Clauses/UsingClause.cs @@ -2,8 +2,17 @@ namespace Carbunql.Clauses; +/// +/// Represents a USING clause used in SQL queries. +/// public class UsingClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified root table, condition, and keys. + /// + /// The root selectable table. + /// The condition used in the USING clause. + /// The keys used in the USING clause. public UsingClause(SelectableTable root, ValueBase condition, IEnumerable keys) { Root = root; @@ -11,12 +20,24 @@ public UsingClause(SelectableTable root, ValueBase condition, IEnumerable + /// Gets the root selectable table. + /// public SelectableTable Root { get; init; } + /// + /// Gets the condition used in the USING clause. + /// public ValueBase Condition { get; init; } + /// + /// Gets the keys used in the USING clause. + /// public IEnumerable Keys { get; init; } + /// + /// Gets the internal queries used in the clause. + /// public IEnumerable GetInternalQueries() { foreach (var item in Root.GetInternalQueries()) @@ -29,6 +50,9 @@ public IEnumerable GetInternalQueries() } } + /// + /// Gets the physical tables used in the clause. + /// public IEnumerable GetPhysicalTables() { foreach (var item in Root.GetPhysicalTables()) @@ -41,7 +65,9 @@ public IEnumerable GetPhysicalTables() } } - + /// + /// Gets the common tables used in the clause. + /// public IEnumerable GetCommonTables() { foreach (var item in Root.GetCommonTables()) @@ -54,6 +80,9 @@ public IEnumerable GetCommonTables() } } + /// + /// Gets the parameters used in the clause. + /// public IEnumerable GetParameters() { foreach (var item in Root.GetParameters()) @@ -69,20 +98,26 @@ public IEnumerable GetParameters() } } - private IEnumerable GetOnTokens(Token? parent) - { - yield return Token.Reserved(this, parent, "on"); - foreach (var token in Condition.GetTokens(parent)) yield return token; - } - + /// + /// Gets the tokens representing the USING clause. + /// public IEnumerable GetTokens(Token? parent) { - //using + // using var t = Token.Reserved(this, parent, "using"); yield return t; foreach (var token in Root.GetTokens(t)) yield return token; - //on + // on foreach (var token in GetOnTokens(t)) yield return token; } -} \ No newline at end of file + + /// + /// Gets the tokens representing the 'on' part of the USING clause. + /// + private IEnumerable GetOnTokens(Token? parent) + { + yield return Token.Reserved(this, parent, "on"); + foreach (var token in Condition.GetTokens(parent)) yield return token; + } +} diff --git a/src/Carbunql/Clauses/ValueBase.cs b/src/Carbunql/Clauses/ValueBase.cs index 0d3f6c8a..d5d800c3 100644 --- a/src/Carbunql/Clauses/ValueBase.cs +++ b/src/Carbunql/Clauses/ValueBase.cs @@ -6,6 +6,9 @@ namespace Carbunql.Clauses; +/// +/// Represents the base class for SQL values used in queries. +/// [MessagePackObject(keyAsPropertyName: true)] [Union(0, typeof(LiteralValue))] [Union(1, typeof(AsArgument))] @@ -23,13 +26,25 @@ namespace Carbunql.Clauses; [Union(13, typeof(ValueCollection))] public abstract class ValueBase : IQueryCommandable { + /// + /// Gets the default name for the value. + /// + /// The default name, which is an empty string. public virtual string GetDefaultName() => string.Empty; + /// + /// Gets or sets the operatable value associated with this value. + /// public OperatableValue? OperatableValue { get; set; } + /// + /// Adds an operatable value with the specified operator and value. + /// + /// The operator to add. + /// The value to add. + /// The current instance of . public ValueBase AddOperatableValue(string @operator, ValueBase value) { - //if (OperatableValue != null) throw new InvalidOperationException(); if (OperatableValue != null) { OperatableValue.Value.AddOperatableValue(@operator, value); @@ -39,13 +54,26 @@ public ValueBase AddOperatableValue(string @operator, ValueBase value) return this; } + /// + /// Gets or sets the recommended name for the value. + /// public string RecommendedName { get; set; } = string.Empty; + /// + /// Adds an operatable value with the specified operator and value. + /// + /// The operator to add. + /// The value to add as a string. + /// The current instance of . public ValueBase AddOperatableValue(string @operator, string value) { return AddOperatableValue(@operator, ValueParser.Parse(value)); } + /// + /// Retrieves all operators associated with this value. + /// + /// An enumerable collection of operators. public IEnumerable GetOperators() { if (OperatableValue == null) yield break; @@ -53,12 +81,16 @@ public IEnumerable GetOperators() foreach (var item in OperatableValue.Value.GetOperators()) yield return item; } + /// + /// Retrieves all query parameters associated with this value. + /// + /// An enumerable collection of query parameters. public virtual IEnumerable GetParameters() { foreach (var item in GetParametersCore()) { yield return item; - }; + } var q = OperatableValue?.GetParameters(); if (q != null) { @@ -69,6 +101,10 @@ public virtual IEnumerable GetParameters() } } + /// + /// Retrieves all internal queries associated with this value. + /// + /// An enumerable collection of internal queries. public IEnumerable GetInternalQueries() { foreach (var item in GetInternalQueriesCore()) @@ -84,6 +120,10 @@ public IEnumerable GetInternalQueries() } } + /// + /// Retrieves all physical tables associated with this value. + /// + /// An enumerable collection of physical tables. public IEnumerable GetPhysicalTables() { foreach (var item in GetPhysicalTablesCore()) @@ -99,6 +139,10 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Retrieves all common tables associated with this value. + /// + /// An enumerable collection of common tables. public IEnumerable GetCommonTables() { foreach (var item in GetCommonTablesCore()) @@ -114,6 +158,10 @@ public IEnumerable GetCommonTables() } } + /// + /// Retrieves all values associated with this value. + /// + /// An enumerable collection of values. public virtual IEnumerable GetValues() { yield return this; @@ -126,17 +174,42 @@ public virtual IEnumerable GetValues() } } } - + /// + /// Gets the core query parameters associated with this value. + /// + /// An enumerable collection of core query parameters. protected abstract IEnumerable GetParametersCore(); + /// + /// Gets the core internal queries associated with this value. + /// + /// An enumerable collection of core internal queries. protected abstract IEnumerable GetInternalQueriesCore(); + /// + /// Gets the core physical tables associated with this value. + /// + /// An enumerable collection of core physical tables. protected abstract IEnumerable GetPhysicalTablesCore(); + /// + /// Gets the core common tables associated with this value. + /// + /// An enumerable collection of core common tables. protected abstract IEnumerable GetCommonTablesCore(); + /// + /// Retrieves the current tokens associated with this value. + /// + /// The parent token. + /// An enumerable collection of tokens. public abstract IEnumerable GetCurrentTokens(Token? parent); + /// + /// Gets all tokens associated with this value. + /// + /// The parent token. + /// An enumerable collection of tokens. public IEnumerable GetTokens(Token? parent) { foreach (var item in GetCurrentTokens(parent)) yield return item; @@ -147,16 +220,28 @@ public IEnumerable GetTokens(Token? parent) } } + /// + /// Converts this value to a bracketed value. + /// + /// A new bracketed value. public BracketValue ToBracket() { return new BracketValue(this); } + /// + /// Converts this value to a where clause. + /// + /// A new where clause. public WhereClause ToWhereClause() { return new WhereClause(this); } + /// + /// Converts this value to its textual representation. + /// + /// The textual representation of this value. public string ToText() { return GetTokens(null).ToText(); diff --git a/src/Carbunql/Clauses/WhenClause.cs b/src/Carbunql/Clauses/WhenClause.cs index b9d284ba..f50f6e32 100644 --- a/src/Carbunql/Clauses/WhenClause.cs +++ b/src/Carbunql/Clauses/WhenClause.cs @@ -3,10 +3,20 @@ namespace Carbunql.Clauses; +/// +/// Represents a collection of conditions for a WHEN clause in a MERGE statement. +/// public class WhenClause : IList, IQueryCommandable { + /// + /// Gets or sets the list of merge conditions. + /// public List Conditions { get; set; } = new(); + /// + /// Retrieves the internal queries associated with this when clause. + /// + /// An enumerable collection of internal queries. public IEnumerable GetInternalQueries() { foreach (var condition in Conditions) @@ -18,6 +28,10 @@ public IEnumerable GetInternalQueries() } } + /// + /// Retrieves the physical tables associated with this when clause. + /// + /// An enumerable collection of physical tables. public IEnumerable GetPhysicalTables() { foreach (var condition in Conditions) @@ -29,6 +43,10 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Retrieves the common tables associated with this when clause. + /// + /// An enumerable collection of common tables. public IEnumerable GetCommonTables() { foreach (var condition in Conditions) @@ -40,6 +58,10 @@ public IEnumerable GetCommonTables() } } + /// + /// Retrieves the query parameters associated with this when clause. + /// + /// An enumerable collection of query parameters. public IEnumerable GetParameters() { foreach (var item in Conditions) @@ -51,11 +73,19 @@ public IEnumerable GetParameters() } } + /// + /// Retrieves the tokens associated with this when clause. + /// + /// The parent token. + /// An enumerable collection of tokens. public IEnumerable GetTokens(Token? parent) { foreach (var condition in Conditions) { - foreach (var item in condition.GetTokens(parent)) yield return item; + foreach (var item in condition.GetTokens(parent)) + { + yield return item; + } } } diff --git a/src/Carbunql/Clauses/WhereClause.cs b/src/Carbunql/Clauses/WhereClause.cs index f2505d78..4d623aef 100644 --- a/src/Carbunql/Clauses/WhereClause.cs +++ b/src/Carbunql/Clauses/WhereClause.cs @@ -3,21 +3,42 @@ namespace Carbunql.Clauses; +using System.Collections.Generic; + +/// +/// Represents a WHERE clause in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class WhereClause : IQueryCommandable { + /// + /// Initializes a new instance of the class with the specified condition. + /// + /// The condition for the WHERE clause. public WhereClause(ValueBase condition) { Condition = condition; } + /// + /// Gets or sets the condition associated with the WHERE clause. + /// public ValueBase Condition { get; init; } + /// + /// Retrieves the query parameters associated with this WHERE clause. + /// + /// An enumerable collection of query parameters. public IEnumerable GetParameters() { return Condition.GetParameters(); } + /// + /// Retrieves the tokens associated with this WHERE clause. + /// + /// The parent token. + /// An enumerable collection of tokens. public IEnumerable GetTokens(Token? parent) { var clause = Token.Reserved(this, parent, "where"); @@ -25,6 +46,10 @@ public IEnumerable GetTokens(Token? parent) foreach (var item in Condition.GetTokens(clause)) yield return item; } + /// + /// Retrieves the internal queries associated with this WHERE clause. + /// + /// An enumerable collection of internal queries. public IEnumerable GetInternalQueries() { foreach (var item in Condition.GetInternalQueries()) @@ -33,6 +58,10 @@ public IEnumerable GetInternalQueries() } } + /// + /// Retrieves the physical tables associated with this WHERE clause. + /// + /// An enumerable collection of physical tables. public IEnumerable GetPhysicalTables() { foreach (var item in Condition.GetPhysicalTables()) @@ -41,6 +70,10 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Retrieves the common tables associated with this WHERE clause. + /// + /// An enumerable collection of common tables. public IEnumerable GetCommonTables() { foreach (var item in Condition.GetCommonTables()) @@ -48,4 +81,4 @@ public IEnumerable GetCommonTables() yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/Clauses/WindowClause.cs b/src/Carbunql/Clauses/WindowClause.cs index 0d5a93b1..643d386d 100644 --- a/src/Carbunql/Clauses/WindowClause.cs +++ b/src/Carbunql/Clauses/WindowClause.cs @@ -4,20 +4,37 @@ namespace Carbunql.Clauses; +/// +/// Represents a WINDOW clause in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class WindowClause : IList, IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public WindowClause() { } + /// + /// Initializes a new instance of the class with the specified window definitions. + /// + /// The window definitions to be added to the clause. public WindowClause(IList definitions) { NamedWindowDefinitions.AddRange(definitions); } + /// + /// Gets the list of named window definitions associated with this WINDOW clause. + /// public List NamedWindowDefinitions { get; private set; } = new(); + /// + /// Retrieves the internal queries associated with this WINDOW clause. + /// + /// An enumerable collection of internal queries. public IEnumerable GetInternalQueries() { foreach (var definition in NamedWindowDefinitions) @@ -29,6 +46,10 @@ public IEnumerable GetInternalQueries() } } + /// + /// Retrieves the query parameters associated with this WINDOW clause. + /// + /// An enumerable collection of query parameters. public IEnumerable GetParameters() { var prm = EmptyParameters.Get(); @@ -41,6 +62,10 @@ public IEnumerable GetParameters() } } + /// + /// Retrieves the physical tables associated with this WINDOW clause. + /// + /// An enumerable collection of physical tables. public IEnumerable GetPhysicalTables() { foreach (var definition in NamedWindowDefinitions) @@ -52,6 +77,10 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Retrieves the common tables associated with this WINDOW clause. + /// + /// An enumerable collection of common tables. public IEnumerable GetCommonTables() { foreach (var definition in NamedWindowDefinitions) @@ -63,6 +92,11 @@ public IEnumerable GetCommonTables() } } + /// + /// Retrieves the tokens associated with this WINDOW clause. + /// + /// The parent token. + /// An enumerable collection of tokens. public IEnumerable GetTokens(Token? parent) { if (!NamedWindowDefinitions.Any()) yield break; @@ -70,12 +104,12 @@ public IEnumerable GetTokens(Token? parent) var clause = Token.Reserved(this, parent, "window"); yield return clause; - var isFisrt = true; + var isFirst = true; foreach (var item in NamedWindowDefinitions) { - if (isFisrt) + if (isFirst) { - isFisrt = false; + isFirst = false; } else { diff --git a/src/Carbunql/Clauses/WindowDefinition.cs b/src/Carbunql/Clauses/WindowDefinition.cs index 56a81ea5..7a8181d5 100644 --- a/src/Carbunql/Clauses/WindowDefinition.cs +++ b/src/Carbunql/Clauses/WindowDefinition.cs @@ -3,40 +3,76 @@ namespace Carbunql.Clauses; +/// +/// Represents a window definition used in a WINDOW clause of a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class WindowDefinition : IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public WindowDefinition() { } + /// + /// Initializes a new instance of the class with the specified name. + /// + /// The name of the window. public WindowDefinition(string name) { Name = name; } + /// + /// Initializes a new instance of the class with the specified partition clause. + /// + /// The partition clause. public WindowDefinition(PartitionClause partitionby) { PartitionBy = partitionby; } + /// + /// Initializes a new instance of the class with the specified order clause. + /// + /// The order clause. public WindowDefinition(OrderClause orderBy) { OrderBy = orderBy; } + /// + /// Initializes a new instance of the class with the specified partition and order clauses. + /// + /// The partition clause. + /// The order clause. public WindowDefinition(PartitionClause partitionby, OrderClause orderBy) { PartitionBy = partitionby; OrderBy = orderBy; } + /// + /// Gets or sets the name of the window. + /// public string Name { get; set; } = string.Empty; + /// + /// Gets or sets the partition clause of the window. + /// public PartitionClause? PartitionBy { get; set; } + /// + /// Gets or sets the order clause of the window. + /// public OrderClause? OrderBy { get; set; } + /// + /// Retrieves the internal queries associated with this window definition. + /// + /// An enumerable collection of internal queries. public IEnumerable GetInternalQueries() { if (!string.IsNullOrEmpty(Name)) yield break; @@ -57,6 +93,10 @@ public IEnumerable GetInternalQueries() } } + /// + /// Retrieves the query parameters associated with this window definition. + /// + /// An enumerable collection of query parameters. public IEnumerable GetParameters() { if (!string.IsNullOrEmpty(Name)) yield break; @@ -78,6 +118,10 @@ public IEnumerable GetParameters() } } + /// + /// Retrieves the physical tables associated with this window definition. + /// + /// An enumerable collection of physical tables. public IEnumerable GetPhysicalTables() { if (!string.IsNullOrEmpty(Name)) yield break; @@ -99,6 +143,10 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Retrieves the common tables associated with this window definition. + /// + /// An enumerable collection of common tables. public IEnumerable GetCommonTables() { if (!string.IsNullOrEmpty(Name)) yield break; @@ -120,6 +168,11 @@ public IEnumerable GetCommonTables() } } + /// + /// Retrieves the tokens associated with this window definition. + /// + /// The parent token. + /// An enumerable collection of tokens. public IEnumerable GetTokens(Token? parent) { if (!string.IsNullOrEmpty(Name)) diff --git a/src/Carbunql/Clauses/WithClause.cs b/src/Carbunql/Clauses/WithClause.cs index c4a0b9f4..9a4eade1 100644 --- a/src/Carbunql/Clauses/WithClause.cs +++ b/src/Carbunql/Clauses/WithClause.cs @@ -4,20 +4,36 @@ namespace Carbunql.Clauses; +// +/// Represents a WITH clause in a query, containing a list of common tables. +/// [MessagePackObject(keyAsPropertyName: true)] public class WithClause : IList, IQueryCommandable { + /// + /// Initializes a new instance of the class. + /// public WithClause() { } + /// + /// Initializes a new instance of the class with the specified common tables. + /// + /// The list of common tables. public WithClause(IList commons) { CommonTables.AddRange(commons); } + /// + /// Gets or sets the list of common tables in the WITH clause. + /// public List CommonTables { get; private set; } = new(); + /// + /// Gets or sets a value indicating whether the WITH clause contains the 'RECURSIVE' keyword. + /// public bool HasRecursiveKeyword { get; set; } = false; public IEnumerable GetTokens(Token? parent, IEnumerable commons) @@ -52,6 +68,11 @@ public IEnumerable GetTokens(Token? parent, IEnumerable comm } } + /// + /// Retrieves the tokens associated with the WITH clause. + /// + /// The parent token. + /// An enumerable collection of tokens. public IEnumerable GetTokens(Token? parent) { foreach (var item in GetTokens(parent, CommonTables)) @@ -60,6 +81,10 @@ public IEnumerable GetTokens(Token? parent) } } + /// + /// Retrieves the query parameters associated with the WITH clause. + /// + /// An enumerable collection of query parameters. public IEnumerable GetParameters() { foreach (var ct in CommonTables) @@ -71,6 +96,10 @@ public IEnumerable GetParameters() } } + /// + /// Retrieves the internal queries associated with the WITH clause. + /// + /// An enumerable collection of internal queries. public IEnumerable GetInternalQueries() { foreach (var commonTable in CommonTables) @@ -82,6 +111,10 @@ public IEnumerable GetInternalQueries() } } + /// + /// Retrieves the physical tables associated with the WITH clause. + /// + /// An enumerable collection of physical tables. public IEnumerable GetPhysicalTables() { foreach (var commonTable in CommonTables) @@ -93,6 +126,10 @@ public IEnumerable GetPhysicalTables() } } + /// + /// Retrieves the common tables associated with the WITH clause. + /// + /// An enumerable collection of common tables. public IEnumerable GetCommonTables() { foreach (var commonTable in CommonTables) diff --git a/src/Carbunql/Clauses/WithoutTimeZoneClause.cs b/src/Carbunql/Clauses/WithoutTimeZoneClause.cs index 3807de0b..e4fa8e23 100644 --- a/src/Carbunql/Clauses/WithoutTimeZoneClause.cs +++ b/src/Carbunql/Clauses/WithoutTimeZoneClause.cs @@ -3,21 +3,38 @@ namespace Carbunql.Clauses; +/// +/// Represents a WITHOUT TIME ZONE clause in a query. +/// [MessagePackObject(keyAsPropertyName: true)] public class WithoutTimeZoneClause : ValueBase { + /// + /// Initializes a new instance of the class. + /// public WithoutTimeZoneClause() { Value = null!; } + /// + /// Initializes a new instance of the class with the specified value. + /// + /// The value to be associated with the clause. public WithoutTimeZoneClause(ValueBase value) { Value = value; } + /// + /// Gets or sets the value associated with the WITHOUT TIME ZONE clause. + /// public ValueBase Value { get; init; } + /// + /// Retrieves the internal queries associated with the clause. + /// + /// An enumerable collection of internal queries. protected override IEnumerable GetInternalQueriesCore() { foreach (var item in Value.GetInternalQueries()) @@ -26,6 +43,11 @@ protected override IEnumerable GetInternalQueriesCore() } } + /// + /// Retrieves the current tokens associated with the clause. + /// + /// The parent token. + /// An enumerable collection of tokens. public override IEnumerable GetCurrentTokens(Token? parent) { foreach (var item in Value.GetTokens(parent)) yield return item; @@ -33,11 +55,19 @@ public override IEnumerable GetCurrentTokens(Token? parent) yield return Token.Reserved(this, parent, "without time zone"); } + /// + /// Retrieves the query parameters associated with the clause. + /// + /// An enumerable collection of query parameters. protected override IEnumerable GetParametersCore() { return Value.GetParameters(); } + /// + /// Retrieves the physical tables associated with the clause. + /// + /// An enumerable collection of physical tables. protected override IEnumerable GetPhysicalTablesCore() { foreach (var item in Value.GetPhysicalTables()) @@ -46,6 +76,10 @@ protected override IEnumerable GetPhysicalTablesCore() } } + /// + /// Retrieves the common tables associated with the clause. + /// + /// An enumerable collection of common tables. protected override IEnumerable GetCommonTablesCore() { foreach (var item in Value.GetCommonTables()) @@ -53,4 +87,4 @@ protected override IEnumerable GetCommonTablesCore() yield return item; } } -} \ No newline at end of file +} diff --git a/src/Carbunql/CreateTableQuery.cs b/src/Carbunql/CreateTableQuery.cs index e1225447..f9ce2540 100644 --- a/src/Carbunql/CreateTableQuery.cs +++ b/src/Carbunql/CreateTableQuery.cs @@ -209,7 +209,7 @@ public DefinitionQuerySet ToNormalize() var queryset = new DefinitionQuerySet(ct); // alter table query normalize - foreach (var item in DefinitionClause.Disasseble()) + foreach (var item in DefinitionClause.Disassemble()) { if (!item.TrySet(ct.DefinitionClause)) { diff --git a/src/Carbunql/UpdateQuery.cs b/src/Carbunql/UpdateQuery.cs index d9b1e127..fef9b671 100644 --- a/src/Carbunql/UpdateQuery.cs +++ b/src/Carbunql/UpdateQuery.cs @@ -40,7 +40,7 @@ public IEnumerable GetInternalQueries() } if (SetClause != null) { - foreach (var value in SetClause.Items) + foreach (var value in SetClause) { foreach (var item in value.GetInternalQueries()) { @@ -89,7 +89,7 @@ public IEnumerable GetPhysicalTables() } if (SetClause != null) { - foreach (var value in SetClause.Items) + foreach (var value in SetClause) { foreach (var item in value.GetPhysicalTables()) { @@ -138,7 +138,7 @@ public IEnumerable GetCommonTables() } if (SetClause != null) { - foreach (var value in SetClause.Items) + foreach (var value in SetClause) { foreach (var item in value.GetCommonTables()) {