chore: initial git load of code space

This commit is contained in:
Thom Lamb
2026-05-12 08:52:33 -05:00
parent 9abada692f
commit 5e467bcc9c
384 changed files with 65960 additions and 2 deletions
@@ -0,0 +1,63 @@
using Strata.SqlTools.SqlBreakdown.Extensions;
namespace Strata.SqlTools.SqlBreakdown.Classes;
/// <summary>
/// Represents a SQL FROM clause with optional JOIN clauses.
/// </summary>
public class SqlFrom
{
private readonly SqlTable _firstTable;
private readonly List<SqlJoin> _joins;
/// <summary>
/// Initializes a new instance of the <see cref="SqlFrom"/> class.
/// </summary>
/// <param name="tableExpression">The primary table expression.</param>
/// <param name="tableAlias">The primary table alias.</param>
public SqlFrom(string tableExpression, string tableAlias)
{
_firstTable = new SqlTable(tableExpression, tableAlias);
_joins = new List<SqlJoin>();
}
/// <summary>
/// Adds a JOIN to the FROM clause.
/// </summary>
/// <param name="table2Expression">The table expression to join.</param>
/// <param name="table2Alias">The alias for the joined table.</param>
/// <param name="table1Column">The column from the primary table.</param>
/// <param name="table2Column">The column from the joined table.</param>
public void Join(string table2Expression, string table2Alias, string table1Column, string table2Column)
{
var theJoin = new SqlJoin(table2Expression, table2Alias, table1Column, table2Column);
Join(theJoin);
}
/// <summary>
/// Adds a pre-constructed JOIN to the FROM clause.
/// </summary>
/// <param name="join">The join to add.</param>
public void Join(SqlJoin join)
{
_joins.Add(join);
}
/// <summary>
/// Returns the SQL FROM clause as a string.
/// </summary>
/// <returns>The FROM clause with all JOINs.</returns>
public override string ToString()
{
var output = new StringBuilderEx();
output.AppendFormat($"\t{_firstTable.TableExpression} {_firstTable.TableAlias}\n");
foreach (var join in _joins)
{
output.AppendFormat($"\tINNER JOIN {join.TableExpression} {join.TableAlias} ON {join.GetJoinOn(_firstTable.TableAlias)}\n");
}
return output.ToString();
}
}