Sql2MermaidErdConverter 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sql2MermaidErdConverter --version 0.1.0
                    
NuGet\Install-Package Sql2MermaidErdConverter -Version 0.1.0
                    
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="Sql2MermaidErdConverter" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sql2MermaidErdConverter" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Sql2MermaidErdConverter" />
                    
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 Sql2MermaidErdConverter --version 0.1.0
                    
#r "nuget: Sql2MermaidErdConverter, 0.1.0"
                    
#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 Sql2MermaidErdConverter@0.1.0
                    
#: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=Sql2MermaidErdConverter&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Sql2MermaidErdConverter&version=0.1.0
                    
Install as a Cake Tool

SqlMmdConverter

.NET License NuGet

Bidirectional converter between SQL DDL and Mermaid Entity Relationship Diagrams (ERD). Automatically generate visual documentation from your database schema or create SQL tables from your Mermaid diagrams!

Features

Bidirectional Conversion

  • SQL DDL → Mermaid ERD diagrams
  • Mermaid ERD → SQL DDL (with dialect support)

🗄️ Multiple SQL Dialects

  • ANSI SQL
  • Microsoft SQL Server (T-SQL)
  • PostgreSQL
  • MySQL
  • SQLite
  • Oracle

📊 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 SqlMmdConverter

Usage

using SqlMmdConverter;
using SqlMmdConverter.Models;

// 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 = SqlMmdConverter.ToMermaid(sqlDdl);
Console.WriteLine(mermaid);

// Convert Mermaid ERD to SQL
var mermaidErd = @"
erDiagram
    Customer ||--o{ Order : places
    Customer {
        int id PK
        string email UK
    }
";

var sql = SqlMmdConverter.ToSql(mermaidErd, SqlDialect.PostgreSql);
Console.WriteLine(sql);

Async Support

// Async conversion
var mermaid = await SqlMmdConverter.ToMermaidAsync(sqlDdl);
var sql = await SqlMmdConverter.ToSqlAsync(mermaidErd, SqlDialect.SqlServer);

Using Dependency Injection

using SqlMmdConverter.Converters;

// Register in your DI container
services.AddSingleton<ISqlToMmdConverter, SqlToMmdConverter>();
services.AddSingleton<IMmdToSqlConverter, MmdToSqlConverter>();

// Use in your code
public class MyService
{
    private readonly ISqlToMmdConverter _sqlConverter;
    private readonly IMmdToSqlConverter _mmdConverter;
    
    public MyService(ISqlToMmdConverter sqlConverter, IMmdToSqlConverter mmdConverter)
    {
        _sqlConverter = sqlConverter;
        _mmdConverter = mmdConverter;
    }
    
    public async Task<string> ConvertSchema(string sql)
    {
        return await _sqlConverter.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"
    }

Mermaid ERD → SQL

Input (Mermaid):

erDiagram
    Customer ||--o{ Order : places
    Customer {
        int id PK
        string name
        string email UK
    }

Output (PostgreSQL):

CREATE TABLE Customer (
    id INTEGER PRIMARY KEY,
    name VARCHAR,
    email VARCHAR UNIQUE
);

CREATE TABLE Order (
    id INTEGER PRIMARY KEY,
    customer_id INTEGER NOT NULL,
    FOREIGN KEY (customer_id) REFERENCES Customer(id)
);

Supported SQL Dialects

Dialect Enum Value Description
ANSI SQL SqlDialect.AnsiSql Standard SQL (default)
SQL Server SqlDialect.SqlServer Microsoft SQL Server (T-SQL)
PostgreSQL SqlDialect.PostgreSql PostgreSQL
MySQL SqlDialect.MySql MySQL
SQLite SqlDialect.Sqlite SQLite
Oracle SqlDialect.Oracle Oracle Database

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

SqlMmdConverter uses battle-tested open-source tools for parsing and conversion:

  • SQLGlot: SQL parsing and dialect translation (31+ SQL dialects)
  • little-mermaid-2-the-sql: Mermaid ERD parsing

The package bundles portable Python and Node.js runtimes, so no external dependencies are required!

Limitations

Current Limitations

  • Views, stored procedures, and triggers are not supported
  • Composite foreign keys have limited support
  • Custom data types may need manual adjustment
  • Some advanced constraints (CHECK, etc.) are not fully supported

Future Enhancements

  • Support for views and stored procedures
  • Enhanced index support
  • Custom data type mapping
  • Schema migration support
  • Diff/comparison tools

Requirements

  • .NET 10.0 or later
  • Windows, Linux, or macOS (x64)

No manual installation of Python or Node.js required! The package includes bundled runtimes.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Support


Made with ❤️ for the database and documentation community

SqlMmdConverter

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
0.2.2 456 11/30/2025
0.2.1 366 11/30/2025
0.2.0 366 11/30/2025
0.1.1 372 11/30/2025
0.1.0 380 11/30/2025

Initial release v0.1.0: SQL to Mermaid ERD conversion with support for 31+ SQL dialects including SQL Server (T-SQL), PostgreSQL, MySQL, Oracle, SQLite, Snowflake, BigQuery, Redshift, Databricks, DuckDB, ClickHouse, Apache Spark, and more. Features: foreign key relationships, primary keys, unique constraints, NOT NULL, and default values. Powered by SQLGlot v28.0.0. Includes embedded Python runtime for zero-config installation.