GithubHelp home page GithubHelp logo

hayago / sqldiagram Goto Github PK

View Code? Open in Web Editor NEW

This project forked from radhifadlillah/sqldiagram

0.0 0.0 0.0 2.25 MB

CLI to generate Entity Relationship Diagram from SQL file

License: MIT License

Go 100.00%

sqldiagram's Introduction

This repository is forked from https://github.com/RadhiFadlillah/sqldiagram

SQLDiagram PayPal Ko-fi

SQLDiagram is CLI app to generate ERD from SQL files. It's inspired by service like DBDiagram or DrawSQL except its offline. It works by parsing your SQL files then convert it to ERD using D2 diagramming language.

Table of Contents

Installation

If go already installed on your system, and $GOBIN is added to your $PATH, then you can install it by simply running:

go install -v github.com/hayago/sqldiagram

Features

  • Works offline.
  • Has decent styling, thanks to D2.
  • Directly parse SQL language so you don't have to learn a new diagramming language.
  • Allow you to group tables in the diagram for better readability, by separating the SQL queries into several files.

Limitations

  • Currently only support MySQL dialect, so no PostgreSQL.
  • Relations only drawn between table and not between columns, which is because of limitations in D2.
  • Sometimes the relational lines will drawn above tables, which again is because of limitations in D2.
  • The output is only in raw D2 language or SVG, so if you need PNG, you need to manually convert it.
  • The relationship is only drawn as normal arrow.

Besides those point, SQLDiagram currently also only support limited DDL commands:

  • CREATE TABLE
  • DROP TABLE
  • ALTER TABLE DROP COLUMNS
  • ALTER TABLE ADD COLUMNS
  • ALTER TABLE RENAME COLUMNS
  • ALTER TABLE CHANGE COLUMNS
  • ALTER TABLE ADD CONSTRAINT

Usage

NAME:
   sqldiagram - generate ERD from SQL file(s) as SVG file

USAGE:
   sqldiagram command [command options] <input-1> ... <input-n>

COMMANDS:
   mysql    generate ERD from MySQL dialect
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h  show help

Each commands has its own help, so you should check it as well. Here is the help for mysql command:

NAME:
   sqldiagram mysql - generate ERD from MySQL dialect

USAGE:
   sqldiagram mysql [command options] [arguments...]

OPTIONS:
   --no-group, --ng                don't render separate file as group (default: false)
   --raw-d2, --raw                 render as raw D2 scripts (default: false)
   --output value, -o value        write to specified path (if empty will use stdout)
   --direction value, --dir value  direction of chart (up|down|right|left, default right)
   --help, -h                      show help

By default it will print the output to stdout, so you could either redirect it:

sqldiagram mysql file.sql > erd.svg

or you can specify the output file:

sqldiagram mysql -o erd.svg file.sql

Examples

Basic Diagram

Here is the generated diagram for Wordpress database, taken from DrawSQL template. To recreate it, download wordpress.sql in example/basic, then run:

sqldiagram --dir down wordpress.sql > erd.svg

Wordpress

Grouped Diagrams

Here is the generated diagram for the same Wordpress database, but now is grouped. To recreate it, download directory example/grouped, then run:

sqldiagram --dir right grouped > erd.svg

Wordpress Grouped

Using TALA Layout

Besides using the open source layout engine, D2 also has its own proprietary layout engine named TALA. In some case, it will give a better and prettier diagram than the open source engine. Unfortunately, its not free and it doesn't provide API to access it directly from Go language.

If you want to use it, you need to generate the layout in D2 language using --raw flag, then copy the result to D2 playground. Do note that you will miss some styling which we done manually in SVG because table styling in D2 is still lacking. For example, here is the diagram for Wordpress using TALA engine:

Wordpress with TALA layout

And here is the grouped diagram using TALA engine:

Wordpress with TALA layout and grouped

Licenses

SQLDiagram is distributed under MIT license, which means you can use and modify it however you want. However, if you make an enhancement for it, if possible, please send a pull request. If you like this project, please consider donating to me either via PayPal or Ko-Fi.

sqldiagram's People

Contributors

radhifadlillah avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.