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,110 @@
using Strata.SqlTools.Breakdowns.LinqToSql;
namespace Strata.SqlTools.Markdown.LinqToSql;
/// <summary>
/// Generates Mermaid diagram markdown from LINQ to SQL QueryBreakdown objects.
/// Creates flowchart visualizations showing the LINQ query structure and flow.
/// </summary>
public class QueryBreakdownGenerator
{
private readonly SqlServer.QueryBreakdownGenerator _baseGenerator;
/// <summary>
/// Initializes a new instance of the QueryBreakdownGenerator class.
/// </summary>
public QueryBreakdownGenerator()
{
_baseGenerator = new SqlServer.QueryBreakdownGenerator();
}
/// <summary>
/// Generates a Mermaid flowchart diagram from a LINQ to SQL QueryBreakdown.
/// </summary>
/// <param name="queryBreakdown">The LINQ QueryBreakdown to visualize.</param>
/// <param name="title">Optional title for the diagram.</param>
/// <returns>A string containing the Mermaid markdown diagram.</returns>
public string GenerateMermaidDiagram(LinqQueryBreakdown queryBreakdown, string? title = null)
{
// Since LinqQueryBreakdown inherits from SqlServer.QueryBreakdown,
// we can use the base generator which works with the shared properties
return _baseGenerator.GenerateMermaidDiagram(queryBreakdown, title);
}
/// <summary>
/// Generates a Mermaid diagram showing the LINQ method call chain.
/// </summary>
/// <param name="queryBreakdown">The LINQ QueryBreakdown to visualize.</param>
/// <param name="title">Optional title for the diagram.</param>
/// <returns>A string containing the Mermaid flowchart showing method calls.</returns>
public string GenerateMethodChainDiagram(LinqQueryBreakdown queryBreakdown, string? title = null)
{
var sb = new System.Text.StringBuilder();
if (!string.IsNullOrWhiteSpace(title))
{
sb.AppendLine($"### {title}");
sb.AppendLine();
}
sb.AppendLine("```mermaid");
sb.AppendLine("flowchart LR");
sb.AppendLine();
if (queryBreakdown.MethodCallChain.Count == 0)
{
sb.AppendLine(" Start([IQueryable]) --> End([Result])");
}
else
{
sb.AppendLine(" Start([IQueryable])");
for (int i = 0; i < queryBreakdown.MethodCallChain.Count; i++)
{
var method = queryBreakdown.MethodCallChain[i];
var nodeId = $"M{i}";
var prevNodeId = i == 0 ? "Start" : $"M{i - 1}";
sb.AppendLine($" {nodeId}[\"{method}\"]");
sb.AppendLine($" {prevNodeId} --> {nodeId}");
}
var lastNodeId = $"M{queryBreakdown.MethodCallChain.Count - 1}";
sb.AppendLine($" {lastNodeId} --> End([Result])");
}
sb.AppendLine("```");
sb.AppendLine();
return sb.ToString();
}
/// <summary>
/// Generates a combined diagram showing both the query structure and method chain.
/// </summary>
/// <param name="queryBreakdown">The LINQ QueryBreakdown to visualize.</param>
/// <param name="title">Optional title for the diagram.</param>
/// <returns>A string containing both diagrams.</returns>
public string GenerateCombinedDiagram(LinqQueryBreakdown queryBreakdown, string? title = null)
{
var sb = new System.Text.StringBuilder();
if (!string.IsNullOrWhiteSpace(title))
{
sb.AppendLine($"## {title}");
sb.AppendLine();
}
// Method chain
sb.AppendLine("### LINQ Method Chain");
sb.AppendLine();
sb.Append(GenerateMethodChainDiagram(queryBreakdown));
// SQL Structure
sb.AppendLine("### SQL Query Structure");
sb.AppendLine();
sb.Append(GenerateMermaidDiagram(queryBreakdown));
return sb.ToString();
}
}