A command-line tool to convert SQL scripts into Entity-Relationship (ER) diagrams.
Designed to work with PostgreSQL syntax.
Report a Bug
·
Request a Feature
Input: test.sql
CREATE TABLE department (
dep_id SERIAL PRIMARY KEY,
dep_name VARCHAR(30),
created_at 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,
created_at TIMESTAMPTZ DEFAULT NOW()
);
CREATE TABLE tasks (
task_id INT,
task_name TEXT
);
Command:
./sql2er-exe test.sql -o erd.svg
Output:
-
Download the binary from the Releases page.
-
Run the tool:
./sql2er-exe test.sql -o erd.svg
-
Clone the repository and navigate to the project root.
-
Build the binary for linux:
stack build cp $(stack path --local-install-root)/bin/sql2er-exe . ./sql2er-exe test.sql -o erd.svg
- Install
wasm32-wasi-cabal
from here - Make sure to download the
9.8
FLAVOUR
.
wasm32-wasi-cabal build sql2er-wasm -f build-sql2er-wasm
cp path/to/sql2er-wasm.wasm .
python3 -m http.server
- Add Changelog
- Add Test Cases
- Support
GENERATED
Constraint - Gracefully Ignore Partitions
- Support
bigserial
- Add Additional Examples
- Enhance Documentation
- Add More Parsing Functions
- Support Interval Data Type
- Support 2D Arrays
For the full list of proposed features and known issues, check out the open issues.
- Syntax Validation:
The parser doesn't validate SQL syntax; it extracts only the necessary information for generating ER diagrams. - Foreign Key Constraints:
Currently supports single-column foreign keys only. - PostgreSQL Specific:
Designed and tested using PostgreSQL 17. - Function Parsing:
Parsing stops atCREATE FUNCTION
statements.
DETACH
USING ...
TABLESPACE
NOT VALID
VALIDATE
INTERVAL
Data Type
This project was inspired by sqldiagram, which focuses on MySQL but lacked robust parsing capabilities.