Skip to content

tusharad/sql2er

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

SQL 2 ER

SQL2ER is a command line tool that takes SQL script as input and generates an ER diagram. The parser is written to adopt PostgreSQL syntax. Report Bug · Request Feature

Example

test.sql

create table department (dep_id serial primary key, dep_name varchar(30), createAt timestamptz default now());
create table employee ( employee_id serial primary key, employee_name varchar(30), employee_age int, 
    dep_id int references department (dep_id) on delete cascade, createAt timestamptz default now());
create table tasks (task_id int, task_name text);
./sql2er-exe test.sql -o erd.svg

Output

Logo

Getting Started

Here are 2 ways to use this tool

  1. Download the binary from release and simply run it.
./sql2er-exe test.sql -o erd.svg
  1. Build from source:

You can download stack via GHCup.

then simply build and run using below command from the root directory of the project.

stack run -- test.sql -o erd.svg

Built With

Haskell

(back to top)

Roadmap

  • Add Changelog
  • Add Additional Examples
  • Add more parsing functions
  • Add more documentation

See the open issues for a full list of proposed features (and known issues).

(back to top)

Limitations:

  • The parser is not smart enough to find syntactical errors in the SQL. It will only extract neccecary information for it to generate an ERD.
  • ForeignKeyConstraint can only handle a single column and not a list of column.
  • The tool is mainly tested and is following postgres version 17 documentation.
  • Not able to parse (to ignore) Create function statements. If it came across create function statement, it will take rest and stop parsing.

(back to top)

does not support:

  • detach
  • using ...
  • tablespace
  • not valid
  • validate
  • begin/commit

Acknowledgments

  • This tool is inspired by sqldiagram but the tool was created for MySQL and the parser was weak.

(back to top)