Laan.Sql.Formatter 0.3.5

dotnet add package Laan.Sql.Formatter --version 0.3.5
                    
NuGet\Install-Package Laan.Sql.Formatter -Version 0.3.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Laan.Sql.Formatter" Version="0.3.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Laan.Sql.Formatter" Version="0.3.5" />
                    
Directory.Packages.props
<PackageReference Include="Laan.Sql.Formatter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Laan.Sql.Formatter --version 0.3.5
                    
#r "nuget: Laan.Sql.Formatter, 0.3.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Laan.Sql.Formatter@0.3.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Laan.Sql.Formatter&version=0.3.5
                    
Install as a Cake Addin
#tool nuget:?package=Laan.Sql.Formatter&version=0.3.5
                    
Install as a Cake Tool

Laan.Sql.Formatter

A T-SQL formatter for .NET. Turns messy or machine-generated SQL into clean, consistently styled code.

Quick Start

using Laan.Sql.Formatter;

// Default options
var engine = new FormattingEngine();
string result = engine.Execute("select id,name from users where active=1");

Output:

SELECT  id,
        name
FROM    users
WHERE   active = 1

Custom Options

var options = new FormattingOptions
{
    IndentSize = 2,
    UseSpaces = true,
    MaxLineLength = 120,
    KeywordCasing = KeywordCasing.Lower,
    BracketSpacing = BracketSpacing.NoSpaces,
    BlankLinesBetweenClauses = 1,
    MaxInlineSelectColumns = 3,
    MaxInlineInsertColumns = 4,
};
var engine = new FormattingEngine(options);

Config File

Drop a .sqlformat.json in your project (or any parent directory) and it will be picked up automatically:

{
  "indentSize": 4,
  "useSpaces": true,
  "maxLineLength": 80,
  "keywordCasing": "Upper",
  "bracketSpacing": "NoSpaces",
  "blankLinesBetweenClauses": 1,
  "maxInlineSelectColumns": 1,
  "maxInlineInsertColumns": 4
}
// Auto-discover from current directory up to root
var options = FormattingOptionsLoader.TryLoadFromHierarchy();
var engine = new FormattingEngine(options);

// Load an explicit file
var engine = FormattingEngine.CreateWithConfigFile("custom.sqlformat.json");

Options Reference

Option Type Default Description
indentSize int 4 Spaces or tabs per indent level
useSpaces bool true Spaces (true) or tabs (false)
maxLineLength int 80 Max line length before wrapping
keywordCasing enum Upper Upper, Lower, or Pascal
bracketSpacing enum NoSpaces NoSpaces(x) · WithSpaces( x )
blankLinesBetweenClauses int 1 Blank lines between major clauses
maxInlineSelectColumns int 1 SELECT columns before wrapping
maxInlineInsertColumns int 4 INSERT columns before wrapping

Targets

  • net472
  • net481
  • net9.0
  • net10.0

Source

github.com/benlaan/sqlformat

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net472 is compatible.  net48 was computed.  net481 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Laan.Sql.Formatter:

Package Downloads
Laan.NHibernate.Appender

SQL Formatter for NHibernate via the Log4net Appender infrastructure

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.5 112 5/14/2026
0.3.4 112 5/14/2026
0.3.3 108 5/14/2026
0.3.2 130 3/18/2026
0.3.1.107 1,450 3/22/2022
0.3.1.70 7,255 6/22/2018