Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tusharad/sql2er
https://github.com/tusharad/sql2er
Last synced: 23 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/tusharad/sql2er
- Owner: tusharad
- License: mit
- Created: 2024-11-03T17:37:16.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-09T08:21:10.000Z (2 months ago)
- Last Synced: 2024-11-09T08:32:57.167Z (2 months ago)
- Language: Haskell
- Size: 188 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Contributors][contributors-shield]][contributors-url]
[![Forks][forks-shield]][forks-url]
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]
[![LinkedIn][linkedin-shield]][linkedin-url]
SQL 2 ER
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
---
## Table of Contents
- [Example](#example)
- [Getting Started](#getting-started)
- [Built With](#built-with)
- [Roadmap](#roadmap)
- [Limitations](#limitations)
- [Unsupported Features](#unsupported-features)
- [Acknowledgments](#acknowledgments)---
## Example
**Input: `test.sql`**
```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:**
```bash
./sql2er-exe test.sql -o erd.svg
```**Output:**
---
## Getting Started
### Option 1: Download Binary
1. Download the binary from the [Releases](https://github.com/tusharad/sql2er/releases) page.
2. Run the tool:```bash
./sql2er-exe test.sql -o erd.svg
```### Option 2: Build from Source
1. Install [Stack](https://docs.haskellstack.org/en/stable/) via [GHCup](https://www.haskell.org/ghcup/).
2. Clone the repository and navigate to the project root.
3. Build the binary for linux:```bash
stack build
cp $(stack path --local-install-root)/bin/sql2er-exe .
./sql2er-exe test.sql -o erd.svg
```### Option 3: Build WASM
1. Install `wasm32-wasi-cabal` from [here](https://gitlab.haskell.org/ghc/ghc-wasm-meta)
2. Make sure to download the `9.8` `FLAVOUR`.```bash
wasm32-wasi-cabal build sql2er-wasm -f build-sql2er-wasm
cp path/to/sql2er-wasm.wasm .
python3 -m http.server
```---
## Built With
[![Haskell][Haskell]][Haskell-url]
---
## Roadmap
- [x] Add Changelog
- [x] Add Test Cases
- [x] Support `GENERATED` Constraint
- [x] Gracefully Ignore Partitions
- [x] Support `bigserial`
- [ ] Add Additional Examples
- [ ] Enhance Documentation
- [ ] Add More Parsing Functions
- [ ] Support Interval Data Type
- [ ] Support 2D ArraysFor the full list of proposed features and known issues, check out the [open issues](https://github.com/tusharad/sql2er/issues).
---
## Limitations
- **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 at `CREATE FUNCTION` statements.---
## Unsupported Features
- `DETACH`
- `USING ...`
- `TABLESPACE`
- `NOT VALID`
- `VALIDATE`
- `INTERVAL` Data Type---
## Acknowledgments
This project was inspired by [sqldiagram](https://github.com/RadhiFadlillah/sqldiagram), which focuses on MySQL but lacked robust parsing capabilities.
[contributors-shield]: https://img.shields.io/github/contributors/tusharad/sql2er.svg?style=for-the-badge
[contributors-url]: https://github.com/tusharad/sql2er/graphs/contributors
[forks-shield]: https://img.shields.io/github/forks/tusharad/sql2er.svg?style=for-the-badge
[forks-url]: https://github.com/tusharad/sql2er/network/members
[stars-shield]: https://img.shields.io/github/stars/tusharad/sql2er.svg?style=for-the-badge
[stars-url]: https://github.com/tusharad/sql2er/stargazers
[issues-shield]: https://img.shields.io/github/issues/tusharad/sql2er.svg?style=for-the-badge
[issues-url]: https://github.com/tusharad/sql2er/issues
[license-shield]: https://img.shields.io/github/license/tusharad/sql2er.svg?style=for-the-badge
[license-url]: https://github.com/tusharad/sql2er/blob/main/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/tushar-adhatrao
[Haskell]: https://img.shields.io/badge/Haskell-5e5086?style=for-the-badge&logo=haskell&logoColor=white
[Haskell-url]: https://www.haskell.org/