https://github.com/protegrity/sqlglot-net
Standalone .NET port of sql-glot-rust, a SQL parser, optimizer, and transpiler library.
https://github.com/protegrity/sqlglot-net
csharp dotnet parser sql transpiler
Last synced: 5 days ago
JSON representation
Standalone .NET port of sql-glot-rust, a SQL parser, optimizer, and transpiler library.
- Host: GitHub
- URL: https://github.com/protegrity/sqlglot-net
- Owner: protegrity
- License: mit
- Created: 2026-06-09T14:54:10.000Z (18 days ago)
- Default Branch: main
- Last Pushed: 2026-06-09T15:50:19.000Z (18 days ago)
- Last Synced: 2026-06-09T16:14:31.937Z (18 days ago)
- Topics: csharp, dotnet, parser, sql, transpiler
- Language: C#
- Homepage: https://github.com/protegrity/sqlglot-net#readme
- Size: 31.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Support: SUPPORT.md
Awesome Lists containing this project
README
# SqlGlot.Net
A standalone .NET port of [sql-glot-rust](https://github.com/protegrity/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
```csharp
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
```bash
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`, and `SUPPORT.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: :` 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.