Sql2MermaidErdConverter 0.2.2
dotnet add package Sql2MermaidErdConverter --version 0.2.2
NuGet\Install-Package Sql2MermaidErdConverter -Version 0.2.2
<PackageReference Include="Sql2MermaidErdConverter" Version="0.2.2" />
<PackageVersion Include="Sql2MermaidErdConverter" Version="0.2.2" />
<PackageReference Include="Sql2MermaidErdConverter" />
paket add Sql2MermaidErdConverter --version 0.2.2
#r "nuget: Sql2MermaidErdConverter, 0.2.2"
#:package Sql2MermaidErdConverter@0.2.2
#addin nuget:?package=Sql2MermaidErdConverter&version=0.2.2
#tool nuget:?package=Sql2MermaidErdConverter&version=0.2.2
Sql2MermaidErdConverter
Convert SQL DDL to Mermaid Entity Relationship Diagrams (ERD). Automatically generate beautiful visual documentation from your database schema!
Note: Currently supports SQL → Mermaid conversion. Mermaid → SQL conversion is planned for a future release.
Features
✨ SQL to Mermaid ERD Conversion
- Convert SQL DDL to beautiful Mermaid ERD diagrams
- Support for 31+ SQL dialects via SQLGlot
- Automatic relationship detection from foreign keys
📊 Full Schema Support
- Tables and columns
- Primary keys
- Foreign keys and relationships
- Unique constraints
- NOT NULL constraints
- DEFAULT values
- Data types
Quick Start
Installation
dotnet add package Sql2MermaidErdConverter
Usage
using Sql2MermaidErdConverter;
// Convert SQL to Mermaid ERD
var sqlDdl = @"
CREATE TABLE Customer (
customer_id INT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
first_name VARCHAR(100) NOT NULL
);
CREATE TABLE Order (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
FOREIGN KEY (customer_id) REFERENCES Customer(customer_id)
);
";
var mermaid = Sql2MermaidErdConverter.ToMermaid(sqlDdl);
Console.WriteLine(mermaid);
// Output: Mermaid ERD diagram with Customer and Order tables and their relationship
Async Support
// Async conversion
var mermaid = await Sql2MermaidErdConverter.ToMermaidAsync(sqlDdl);
Using Dependency Injection
using Sql2MermaidErdConverter.Converters;
// Register in your DI container
services.AddSingleton<ISqlToMmdConverter, SqlToMmdConverter>();
// Use in your code
public class MyService
{
private readonly ISqlToMmdConverter _converter;
public MyService(ISqlToMmdConverter converter)
{
_converter = converter;
}
public async Task<string> ConvertSchema(string sql)
{
return await _converter.ConvertAsync(sql);
}
}
Examples
SQL → Mermaid ERD
Input (SQL):
CREATE TABLE Customer (
customer_id INT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
first_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE Order (
order_id INT PRIMARY KEY,
customer_id INT NOT NULL,
order_date DATE NOT NULL,
total_amount DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (customer_id) REFERENCES Customer(customer_id)
);
Output (Mermaid):
erDiagram
Customer ||--o{ Order : customer_id
Customer {
int customer_id PK
varchar email UK "NOT NULL"
varchar first_name "NOT NULL"
varchar last_name "NOT NULL"
timestamp created_at "DEFAULT CURRENT_TIMESTAMP"
}
Order {
int order_id PK
int customer_id FK "NOT NULL"
date order_date "NOT NULL"
decimal total_amount "NOT NULL"
}
Supported SQL Dialects (Input)
The converter can parse SQL DDL from 31+ different SQL dialects thanks to SQLGlot. Common dialects include:
- ANSI SQL (Standard SQL)
- Microsoft SQL Server (T-SQL) - with automatic bracket removal
- PostgreSQL
- MySQL / MariaDB
- SQLite
- Oracle
- IBM DB2
- Snowflake
- BigQuery
- Redshift
- And 20+ more!
The tool automatically detects and handles dialect-specific syntax variations.
Supported Data Types
Numeric Types
- INT, INTEGER, BIGINT, SMALLINT
- DECIMAL, NUMERIC
- FLOAT, REAL, DOUBLE
String Types
- VARCHAR, NVARCHAR
- CHAR, NCHAR
- TEXT
Date/Time Types
- DATE, TIME
- DATETIME, TIMESTAMP
Other Types
- BOOLEAN, BOOL
- BINARY, VARBINARY
- UUID, UNIQUEIDENTIFIER
Architecture
Sql2MermaidErdConverter uses SQLGlot, a battle-tested open-source SQL parser and transpiler that supports 31+ SQL dialects.
How it works:
- Your SQL DDL is cleaned and normalized (removes T-SQL brackets, fixes syntax quirks)
- SQLGlot parses the SQL into an Abstract Syntax Tree (AST)
- The converter extracts tables, columns, constraints, and relationships
- Mermaid ERD syntax is generated with proper formatting
The package bundles a portable Python runtime with SQLGlot pre-installed, so no external dependencies are required!
Limitations
Current Version (v0.2.x)
- One-way conversion only: SQL → Mermaid (Mermaid → SQL planned for v1.0)
- Views, stored procedures, and triggers are not supported
- Composite foreign keys have limited support
- Some advanced constraints (CHECK, etc.) are not fully supported
- Indexes are documented as comments, not visualized in the diagram
Planned for Future Releases
- v1.0: Mermaid → SQL conversion (bidirectional support)
- Support for views and stored procedures
- Enhanced index visualization
- Custom data type mapping
- Schema migration and diff tools
Requirements
- .NET 10.0 or later
- Windows, Linux, or macOS (x64)
No manual installation of Python required! The package includes a bundled Python runtime.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- SQLGlot by Toby Mao - Powerful SQL parser and transpiler supporting 31+ dialects
- Mermaid.js by Knut Sveidqvist - Beautiful diagram and flowchart rendering
Support
Made with ❤️ for the database and documentation community
| 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.
v0.2.2: Corrected README to accurately reflect SQL→Mermaid one-way conversion (Mermaid→SQL planned for v1.0). v0.2.1: Fixed README heading and updated logo. v0.2.0: T-SQL bracket removal, MS Access syntax support. v0.1.1: FK extraction fixes. v0.1.0: Initial release. Powered by SQLGlot v28.0.0.