Thom LambandClaude Opus 4.7 f4d318b35c
SonarQube Analysis / sonarqube (pull_request) Successful in 3m39s
refactor(dedup): IQueryBreakdownCollectionView eliminates Markdown adapter classes
Replaces the per-dialect <c>Adapter</c> nested classes (which were
themselves the leftover duplication after PR #22's first cut) with a
shared <c>IQueryBreakdownCollectionView</c> interface implemented
directly on each dialect's <c>QueryBreakdownCollection</c>.

New foundation types in <c>Strata.SqlTools.Breakdowns.SqlServer</c>:

- **<c>IQueryBreakdownCollectionView</c>** — dialect-neutral view
  exposing QueryCount, UniqueParameterCount, TotalSelectedColumns,
  UniqueTableCount, QueriesForReport (typed against the SqlServer
  <c>QueryBreakdown</c> base — PG/Snowflake satisfy via <c>IReadOnlyList</c>
  covariance), and ParameterUsageRecords.
- **<c>ParameterUsageRecord</c>** — record type for per-parameter usage
  stats, projected from each dialect's <c>ParameterUsageReport</c>.

The three dialect <c>QueryBreakdownCollection</c> classes now implement
the interface explicitly — a handful of one-line forwarders per class.
The Markdown layer's old <c>ICollectionMarkdownData</c> interface and
the writer-internal <c>ParameterUsageRow</c> type are deleted; the
template and writer take <c>IQueryBreakdownCollectionView</c> and
<c>ParameterUsageRecord</c> directly.

Net effect on the Markdown wrappers:
- <c>Markdown.SqlServer.QueryBreakdownCollectionGenerator</c> loses
  its <c>Adapter</c> nested class and its 6 forwarders pass <c>collection</c>
  straight through.
- <c>Markdown.PostgreSql.QueryBreakdownCollectionGenerator</c> ditto.
- <c>Markdown.Snowflake.QueryBreakdownCollectionGenerator</c> migrated
  to the same pattern; its dialect-specific
  <c>GenerateSnowflakeFeaturesAnalysis</c> and feature-aware
  <c>QueryCompositionReport</c> callback stay intact (they still call
  <c>CollectionReportWriter</c> directly).

Public API additions: <c>IQueryBreakdownCollectionView</c> and
<c>ParameterUsageRecord</c> (both new, both opt-in). Public API
removals: none — the dialect <c>ParameterUsageReport</c> classes are
untouched and the dialect <c>QueryBreakdownCollectionGenerator</c>
public surface is identical.

All 1180 tests stay green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 17:47:12 -05:00
2026-05-12 08:46:05 -05:00
2026-05-12 08:52:33 -05:00

Strata.SqlTools

build

General Information

This library provides SQL utilities for parsing, analyzing, and manipulating SQL queries programmatically. It includes:

Core Features

  • QueryBreakdown: Deep parsing of SELECT statements into component parts (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY)
  • Expression Trees: Type-safe expression building with operator overloading
  • WITH Clause Support: Common Table Expressions (CTEs) parsing and generation
  • Comment Preservation: Round-trip parsing that preserves SQL comments

SQL Dialect Support

  • SQL Server: Full T-SQL dialect support with bracket identifiers and @parameters
  • PostgreSQL: PostgreSQL syntax with $n positional and :named parameters
  • Snowflake: Snowflake SQL dialect with :parameters and uppercase identifiers
  • LINQ to SQL: Expression tree analysis for IQueryable queries

Visualization

  • Mermaid Diagrams: Generate flowcharts, sequence diagrams, and ER diagrams
  • Query Structure Visualization: Visual representation of query clauses and flow
  • LINQ Method Chain Diagrams: Visualize LINQ query execution pipelines
  • Collection Analysis: Batch query analysis with parameter usage reports

Integration

  • Entity Framework Core: Persist and query QueryBreakdown objects with EF Core

Credits

This library is developed and maintained by Strata Decision Technology

Documentation

Comprehensive documentation is available in the docs folder:

Core Documentation

Dialect-Specific Guides

Integration & Visualization

See the documentation index for a complete list.

Branching and Versioning

branch version format example
main #.#.# 1.2.3
feature/* #.#+1.0-featureName.# 1.3.0-newfeat.1
fix/* #.#.#+1-fixName.# 1.2.4-bug.1

See our confluence page for more information

Usage

Build and Test

Build the solution:

dotnet build Strata.SqlTools.sln

Run tests:

dotnet test Strata.SqlTools.sln

TestContainer Integration Tests

The testContainers folder contains real-world integration tests for PostgreSQL and SQL Server using Docker containers. These tests are not included in the main solution to keep CI/CD builds fast and avoid Docker dependencies in the build pipeline.

Requirements:

  • Docker Desktop installed and running
  • Tests take 1-2 minutes to run (container startup time)

Run TestContainer Tests:

# Run SQL Server integration tests (18 tests)
dotnet test testContainers/Strata.SqlTools.SqlServer.TestContainers

# Run PostgreSQL integration tests (17 tests)
dotnet test testContainers/Strata.SqlTools.PostgreSql.TestContainers

# Run all TestContainer tests (35 tests)
dotnet test testContainers/Strata.SqlTools.SqlServer.TestContainers
dotnet test testContainers/Strata.SqlTools.PostgreSql.TestContainers

Note: These integration tests are excluded from the main solution to support Docker-less build environments. They remain fully functional for local development and can be run independently as shown above.

Core & Dialect Packages

  • Strata.SqlTools - Core SQL parsing and expression library
  • Strata.SqlTools.SqlServer - SQL Server (T-SQL) specific implementations
  • Strata.SqlTools.PostgreSql - PostgreSQL specific implementations with parameter analysis
  • Strata.SqlTools.Snowflake - Snowflake SQL specific implementations
  • Strata.SqlTools.LinqToSql - LINQ to SQL query analysis and expression tree parsing

Integration & Visualization Packages

  • Strata.SqlTools.Markdown - Mermaid diagram generation for all SQL dialects
  • Strata.SqlTools.EFCore - Entity Framework Core integration for QueryBreakdown persistence
  • Strata.SqlTools.Rules - Rule engine for SQL query validation and analysis

NuGet Packages

This solution produces the following NuGet packages:

  • Strata.SqlTools - Core SQL parsing and expression library
  • Strata.SqlTools.SqlServer - SQL Server (T-SQL) specific implementations
  • Strata.SqlTools.Snowflake - Snowflake SQL specific implementations

Package Features

Package Metadata:

  • Symbol packages (snupkg) for debugging support
  • Source Link enabled for debugging into package source
  • XML documentation included
  • MIT License
  • README included in package

Code Quality:

  • .NET 9.0 target framework
  • Nullable reference types enabled
  • .NET Analyzers and code style enforcement
  • Full XML documentation on public APIs
  • EditorConfig for consistent code style

Creating NuGet Packages

Build and create packages:

dotnet pack Strata.SqlTools.sln -c Release

Packages will be output to the bin/Release folders of each project.

Create a specific package:

dotnet pack src/Strata.SqlTools/Strata.SqlTools.csproj -c Release -o ./nupkg

Publishing to NuGet

Validate package before publishing:

dotnet tool install -g dotnet-validate
dotnet validate package nupkg/Strata.SqlTools.1.0.0.nupkg

Publish to NuGet.org:

dotnet nuget push nupkg/Strata.SqlTools.1.0.0.nupkg --api-key YOUR_API_KEY --source https://api.nuget.org/v3/index.json

Publishing Checklist

Before publishing to NuGet.org:

  • Verify all public APIs have XML documentation
  • Run full test suite and ensure 100% pass rate
  • Update version number according to SemVer
  • Update PackageReleaseNotes with changes
  • Test package installation in a clean project
  • Validate package contents using dotnet validate
  • Push symbols to symbol server for debugging support

Development

Prerequisites

  • .NET 9.0 SDK or later
  • Visual Studio 2022 or VS Code with C# extension

Code Quality Tools

  • Analyzers: Enabled for all projects
  • Code Coverage: Run tests with coverage using your preferred tool
  • SonarQube: Static analysis issues are tracked

API Guidelines

  • All public APIs must have XML documentation
  • Follow .NET API Design Guidelines
  • Maintain backward compatibility within major versions (SemVer)
S
Description
Sql Query Breakdown Utilities
Readme MIT
1.8 MiB
Languages
C# 99.9%
PowerShell 0.1%