CSharpDB.Sql
1.2.0
dotnet add package CSharpDB.Sql --version 1.2.0
NuGet\Install-Package CSharpDB.Sql -Version 1.2.0
<PackageReference Include="CSharpDB.Sql" Version="1.2.0" />
<PackageVersion Include="CSharpDB.Sql" Version="1.2.0" />
<PackageReference Include="CSharpDB.Sql" />
paket add CSharpDB.Sql --version 1.2.0
#r "nuget: CSharpDB.Sql, 1.2.0"
#:package CSharpDB.Sql@1.2.0
#addin nuget:?package=CSharpDB.Sql&version=1.2.0
#tool nuget:?package=CSharpDB.Sql&version=1.2.0
CSharpDB.Sql
SQL tokenizer, recursive-descent parser, and abstract syntax tree (AST) for the CSharpDB embedded database engine.
Overview
CSharpDB.Sql provides a complete SQL front-end: a single-pass tokenizer, a recursive-descent parser, and a rich AST hierarchy. It transforms SQL text into strongly-typed statement and expression objects that downstream components (query planner, execution engine) consume. Zero external dependencies.
Features
- 108 token types covering SQL keywords, literals, identifiers,
@parameters, operators, and punctuation - Full DDL/DML parsing: CREATE/DROP/ALTER TABLE, CREATE/DROP INDEX, CREATE/DROP VIEW, CREATE/DROP TRIGGER
- Rich query support: SELECT with JOINs (INNER, LEFT, RIGHT, CROSS), WHERE, GROUP BY, HAVING, ORDER BY, LIMIT/OFFSET, CTEs (WITH)
- Expression tree: binary/unary operators, LIKE, IN, BETWEEN, IS NULL, aggregate functions (COUNT, SUM, AVG, MIN, MAX with DISTINCT)
- Fast-path optimizers:
TryParseSimpleSelectandTryParseSimplePrimaryKeyLookupdetect common patterns and skip full AST construction
Usage
using CSharpDB.Sql;
// Parse a SQL statement
var statements = Parser.Parse("SELECT id, name FROM users WHERE age > 21");
// The result is a list of strongly-typed AST nodes
if (statements[0] is SelectStatement select)
{
Console.WriteLine($"Table: {select.From}");
Console.WriteLine($"Columns: {select.Columns.Count}");
Console.WriteLine($"Has WHERE: {select.Where != null}");
}
// Parse DDL
var ddl = Parser.Parse("""
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
user_id INTEGER,
total REAL
)
""");
// Fast-path detection for simple queries
if (Parser.TryParseSimplePrimaryKeyLookup(sql, out var lookup))
{
// Skip full parsing for SELECT ... WHERE pk = value
}
AST Hierarchy
Statements: CreateTableStatement, DropTableStatement, InsertStatement, SelectStatement, UpdateStatement, DeleteStatement, AlterTableStatement, CreateIndexStatement, DropIndexStatement, CreateViewStatement, DropViewStatement, CreateTriggerStatement, DropTriggerStatement, WithStatement
Expressions: LiteralExpression, ParameterExpression, ColumnRefExpression, BinaryExpression, UnaryExpression, LikeExpression, InExpression, BetweenExpression, IsNullExpression, FunctionCallExpression
Table References: SimpleTableRef, JoinTableRef (Inner, LeftOuter, RightOuter, Cross)
Installation
dotnet add package CSharpDB.Sql
Dependencies
CSharpDB.Core- shared type system and schema definitions
Related Packages
| Package | Description |
|---|---|
| CSharpDB.Execution | Query planner and operator tree that consumes this AST |
| CSharpDB.Engine | Embedded database engine |
License
MIT - see LICENSE for details.
| 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
- CSharpDB.Core (>= 1.2.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CSharpDB.Sql:
| Package | Downloads |
|---|---|
|
CSharpDB.Engine
Lightweight embedded SQL database engine for .NET. Single-file storage, WAL durability, concurrent readers, and a typed Collection<T> NoSQL API. |
|
|
CSharpDB.Execution
Query planner, operator tree, and expression evaluator for the CSharpDB embedded database. |
GitHub repositories
This package is not used by any popular GitHub repositories.