SqlGlot.Net
0.9.0
dotnet add package SqlGlot.Net --version 0.9.0
NuGet\Install-Package SqlGlot.Net -Version 0.9.0
<PackageReference Include="SqlGlot.Net" Version="0.9.0" />
<PackageVersion Include="SqlGlot.Net" Version="0.9.0" />
<PackageReference Include="SqlGlot.Net" />
paket add SqlGlot.Net --version 0.9.0
#r "nuget: SqlGlot.Net, 0.9.0"
#:package SqlGlot.Net@0.9.0
#addin nuget:?package=SqlGlot.Net&version=0.9.0
#tool nuget:?package=SqlGlot.Net&version=0.9.0
SqlGlot.Net
A standalone .NET port of sql-glot-rust — a SQL parser, optimizer, and transpiler library.
This project is a pure-managed C# implementation with no native dependencies, suitable for ADO.NET drivers, EF Core providers, AOT-compiled apps, Blazor WebAssembly, Azure Functions, and other .NET hosts.
Status
This is a foundational port that mirrors the Rust crate layout 1:1, so further porting is mechanical. The initial drop covers the end-to-end happy path:
| Module | Rust LOC | .NET status |
|---|---|---|
tokens/ |
~2,000 | ✅ Lexer ported (literals, operators, identifiers, comments, keywords) |
errors/ |
~30 | ✅ Exception hierarchy |
dialects/ |
~1,000 | ✅ Dialect enum + quoting rules (30 dialects) |
ast/types.rs |
~2,300 | ✅ Statement + Expr subset (SELECT path, full operator set) |
parser/sql_parser.rs |
~4,000 | ✅ Recursive-descent SELECT/FROM/JOIN/WHERE/GROUP BY/HAVING/ORDER BY/LIMIT |
generator/sql_generator.rs |
~3,300 | ✅ Visitor-based emitter with dialect quoting |
builder/ |
~1,500 | ⏳ Fluent builder API (TODO) |
optimizer/ |
~3,000 | ⏳ TODO |
executor/, planner/, schema/, diff/ |
~4,000 | ⏳ TODO |
Roundtrips today: SELECT … FROM … [JOIN …] [WHERE …] [GROUP BY …] [HAVING …] [ORDER BY …] [LIMIT n [OFFSET n]] with full expression grammar (arithmetic,
comparison, logical, IS NULL, IN, BETWEEN, LIKE, CASE, CAST, function calls,
parenthesised sub-expressions, qualified columns).
Layout
sqlglot-net/
├── SqlGlot.Net.sln
├── src/
│ └── SqlGlot.Net/
│ ├── SqlGlot.Net.csproj
│ ├── SqlGlot.cs # public Parse / Generate / Transpile API
│ ├── Errors/
│ │ └── SqlGlotException.cs
│ ├── Dialects/
│ │ └── Dialect.cs # 30-dialect enum + QuoteStyle helpers
│ ├── Tokens/
│ │ ├── TokenType.cs
│ │ ├── Token.cs
│ │ └── Tokenizer.cs
│ ├── Ast/
│ │ ├── Statement.cs # Statement abstract + sub-records
│ │ ├── Expr.cs # Expr abstract + sub-records
│ │ └── Common.cs # QuoteStyle, BinaryOperator, etc.
│ ├── Parser/
│ │ └── SqlParser.cs
│ └── Generator/
│ └── SqlGenerator.cs
└── tests/
└── SqlGlot.Net.Tests/
├── SqlGlot.Net.Tests.csproj
├── TokenizerTests.cs
├── ParserTests.cs
├── GeneratorTests.cs
└── RoundtripTests.cs
Quick start
using SqlGlot.Net;
using SqlGlot.Net.Dialects;
// Parse
var ast = SqlGlot.Parse("SELECT a, b FROM t WHERE a > 1", Dialect.Ansi);
// Generate
var sql = SqlGlot.Generate(ast, Dialect.Postgres);
// => SELECT a, b FROM t WHERE a > 1
// Transpile in one call
var tsql = SqlGlot.Transpile(
"SELECT \"id\" FROM users",
from: Dialect.Postgres,
to: Dialect.Tsql);
// => SELECT [id] FROM users
Build & test
dotnet build
dotnet test
dotnet pack src/SqlGlot.Net/SqlGlot.Net.csproj -c Release
Targets net10.0. No third-party runtime dependencies.
Project health
- CI runs on GitHub Actions for every push and pull request.
- Community support and contribution guidance live in
CONTRIBUTING.md,SECURITY.md, andSUPPORT.md. - The package metadata is set up for public NuGet publishing.
Porting strategy
The Rust source is the source of truth. Each .NET type carries an
// Rust: <path>:<symbol> comment that points to the originating Rust item so
syncing future Rust changes is a line-by-line exercise.
Roadmap order (recommended): expression grammar gaps (window functions, EXTRACT, INTERVAL) → INSERT/UPDATE/DELETE/MERGE → CREATE/ALTER/DROP → builder fluent API → optimizer passes → schema & planner → diff/executor.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.