Giter Club home page Giter Club logo

md2sql's Introduction

md2sql

Generate SQL/ERD from Markdown list.

$ go install github.com/shibukawa/md2sql...

You can try on your browser.

Example

Simple Example

  • All table should start "table: " prefix.
  • Each column is formatted in "name: type".
* table: BasicTable
  * id: integer
  * name: string
$ md2sql -f sql simple.md

You can get the following SQL:

CREATE TABLE BasicTable(
    id INTEGER NOT NULL,
    name TEXT NOT NULL
);

Also you can get the PlantUML and Mermaid.js ERD by using -f plantuml or -f mermaid:

@startuml

entity BasicTable {
  --
  *id:INTEGER
  *name:TEXT
}

@enduml
erDiagram

BasicTable {
  INTEGER id
  TEXT name
}
Loading

Basic Example

You can specify primary key, index and foreign key.

  • @ prefix of name means primary key. If you omit type, it becomes auto incremental field.
  • $ prefix of name means index.
  • * prefix of type field means foreign key.
* table: User
    * @id
    * name: string
    * $email: string
    * age: integer
    * job: *Job.id

* table: Job
    * @id
    * name: string

You can get the following SQL:

CREATE TABLE User(
    id SERIAL,
    name TEXT NOT NULL,
    email TEXT NOT NULL,
    age INTEGER NOT NULL,
    job INTEGER NOT NULL,
    PRIMARY KEY(id),
    FOREIGN KEY(job) REFERENCES Job(id)
);

CREATE UNIQUE INDEX INDEX_User_email ON User(email);

CREATE TABLE Job(
    id SERIAL,
    name TEXT NOT NULL,
    PRIMARY KEY(id)
);

Associative Entity

You can specify Associative Entity by using [] suffix.

* table: User
    * @id
    * name: string
    * age: integer
    * jobs: *Job.id[]

* table: Job
    * @id
    * name: string

You can get the following SQL:

CREATE TABLE User(
    id SERIAL,
    name TEXT NOT NULL,
    age INTEGER NOT NULL,
    PRIMARY KEY(id)
);

CREATE TABLE Job(
    id SERIAL,
    name TEXT NOT NULL,
    PRIMARY KEY(id)
);

CREATE TABLE User_jobs(
    id SERIAL PRIMARY KEY,
    User_id INTEGER,
    Job_id INTEGER,
    FOREIGN KEY(User_id) REFERENCES User(id),
    FOREIGN KEY(Job_id) REFERENCES Job(id)
);

Stereotype

PlantUML generator can represent stereotypes of tables. There are 7 types you can use:

label meaning Mark
table: Generic table. E
master: Its represents system. M
tran: or transaction: It represents activity. T
summary: It keeps cache of query result. E
work: Temporary table W
view: View V
associativeentity: Associative Entity A

And tables that has -(minus) or _(underscore) prefixed means dependent tables.

* master: Users
    * @id
    * name: string
    * age: integer
    * jobs: *Job.id[]

* -tran: Tests
    * @user: Users.id
    * @date: Date
    * score: integer

Web Interface

This tool also provides a web interface.

$ cd cmd/frontend
$ npm run dev

It uses plantuml.com to generate image from PlantUML source. You can run plantuml server locally by using docker:

$ docker compose up -d
$ cd cmd/frontend
$ NEXT_PUBLIC_PLANTUML_SERVER=http://localhost:18080 npm run dev

License

AGPL

md2sql's People

Contributors

shibukawa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

go-sqlparser

md2sql's Issues

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.