Skip to content

sattosan/sql2mermaid-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


PyPI - License GitHub Workflow Status (with event) PyPI PyPI - Python Version

sql2mermaid-cli

sql2mermaid-cli is a CLI tool that converts SQL query into mermaid.js style!.

output-image

Required

Python >=3.8.1

Installation

To install sql2mermaid-cli, use the following command:

$ pip install sql2mermaid-cli

Getting Started

As a preparation, create a sample SQL file.

$ echo "with bar as (select * from baz)\n\
select * from foo inner join bar on foo.id = bar.id\n"> input.sql

The basic usage of sql2mermaid-cli is as follows:

$ sql2mermaid-cli -i input.sql

This will output the mermaid diagram to the console:

graph LR

bar([bar])
root([root])

baz[(baz)]
foo[(foo)]

bar --> baz
root --> foo
root --> bar

The Mermaid diagram that is outputted can be visualized on the Mermaid Live Editor website.

Mermaid Live Editor

Options

To save the output to a file, use the -o option followed by the path to the output file:

$ sql2mermaid-cli -i input.sql -o output.txt

By default, the output format is plain text. To output the mermaid diagram in markdown format, use the -m option:

$ sql2mermaid-cli -i input.sql -o output.md -m

You can also specify either "upper" or "lower" after the -d option to display the join type of SQL in the mermaid diagram.

$ sql2mermaid-cli -i input.sql -d upper

This will output the mermaid diagram to the console:

graph LR

bar([bar])
foo([foo])

root[(root)]
baz[(baz)]
foo.id[(foo.id)]
bar.id[(bar.id)]

bar -- FROM --> baz
bar -- FROM --> foo
foo -- INNER JOIN --> bar

Author

License

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

About

CLI tool to generate mermaid from sql query.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages