Code Monkey home page Code Monkey logo

erdiagram's Introduction

ERDiagram

Define an entity-relationship diagram, then generate the database creation script, OOP classes, and much more!

License Contributor Covenant

Coverage statements Coverage branches Coverage functions Coverage lines

Table of contents

Live demo & CLI

You can try ERDiagram online using the ERDiagram playground application. There you will find some code examples that are very useful for learning the ERDiagram language.

There is also a work-in-progress CLI version of ERDiagram. Check it out! ๐Ÿ™‚

Installation

Installation steps for users

You can find the installation steps of the library in the Library usage document.

Installation steps for contributors

Download the project

  1. Clone the repository
git clone https://github.com/nestorrente/erdiagram.git
  1. Access to the project's directory
cd erdiagram
  1. Install dependencies
npm install

Run tests and build

For running the tests and generating the badges for the README file, you can use the following command:

npm run test

For building the library, you can use the following command:

npm run build

Documentation

  • ERDiagram language: learn how to define entities and relationships.

  • ERDiagram library: installation, basic concepts, configuration and examples.

  • Entity-relationship model conversion:

    • Database model: learn how entities and relationships are modeled as tables and columns.
    • Class model: learn how entities and relationships are modeled as OOP classes.
  • Supported output formats:

    • Database creation script (SQL):
      • MySQL
      • Oracle DB
      • PostgreSQL
      • SQLite
      • SQL Server
    • OOP classes/interfaces:
      • Java (includes Bean Validation and JPA support)
      • TypeScript
    • Diagram code:
      • PlantUML
      • Nomnoml

Contributing

This is a side project I'm working on during my spare time, so I'd be very happy if you want to contribute ๐Ÿ˜€ bug report, suggestions, pull requests, or any other kind of feedback are really appreciated.

Please contribute using GitHub Flow. Create a branch from the develop one, add commits, and open a pull request.

Please note we have a code of conduct, please follow it in all your interactions with the project.

If you want to get in touch with the author, you can contact me through LinkedIn or email.

Wish list

This is a small list of features/tools that I'll be very happy to have:

  • More database engines support.
  • More OOP languages support.
  • Syntax highlight for some text editors or IDEs (Sublime Text, Atom, IntelliJ IDEA, VS Code, ...).
  • XSD / JSON schema generation.
  • Liquibase files generation.
  • Any other cool stuff ๐Ÿ˜›

erdiagram's People

Contributors

nestorrente avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

erdiagram's Issues

Three levels of modeling

There are three different levels of modeling, like below. The most helpful one is obviously the Physical one, but when the database is huge, a couple of hundreds of tables is just so normal these day, the more abstracted forms will be more preferable, as the number of tables grow.

Machine generated diagrams are the perfect solution for such problem, and hope erdiagram can support different levels of diagrams someday.

Thanks

Conceptual

ClipCapIt-140625-111749.PNG

  • the most abstract form of data model
  • simplified, helpful for communicating ideas to a wide range of stakeholders

Logical

ClipCapIt-140625-112254.PNG

  • contains a bit more details than the almost-empty conceptual one, which will include all key structure data elements for the relationships (for table joining; and no more further details than that, unlike the borrowed image above)

Physical

ClipCapIt-140625-112702.PNG

  • this is only a borrowed image; The key is to contain all fields, which has already been implemented. IF the PK/FK can be marked out, then that'd be super.

Hide methods on PlantUML diagram

Currently, we are hiding the methods and members in conceptual diagrams (as both are empty). However, methods are not being hidden in logical diagrams, even when the diagram doesn't include any method.

We should ensure that the hide methods directive is used in both cases.

Prevent naming collisions

There are several scenarios where generated code (SQL, TS or Java) can produce several tables, columns or classes with the same name.

For example, if you define the following ER model:

User
    id int

Users

Role
    userId int

UsersRole

Role -> User
User *<->* Role

The following SQL code is produced for SQLite:

PRAGMA foreign_keys = OFF;

CREATE TABLE "users" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "id" INTEGER NOT NULL
);

CREATE TABLE "users" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);

CREATE TABLE "roles" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "user_id" INTEGER NOT NULL,
    "user_id" INTEGER NOT NULL,
    CONSTRAINT "roles_user_id_unique" UNIQUE ("user_id"),
    CONSTRAINT "roles_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "users" ("id")
);

CREATE TABLE "users_roles" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT
);

CREATE TABLE "users_roles" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "user_id" INTEGER NOT NULL,
    "role_id" INTEGER NOT NULL,
    CONSTRAINT "users_roles_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "users" ("id"),
    CONSTRAINT "users_roles_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "roles" ("id")
);

PRAGMA foreign_keys = ON;

The users and users_roles tables are duplicated, and the same happends to the roles.user_id column. We must implement one of the following solutions:

  • Throw an error when this happen.
  • Add an incremental suffix to the generated tables and columns
    • For example, if the Role entity has an explicit user_id column, the column produced by the Role -> User relationship must be named user_id2 or something similar.
    • The same applies to the corresponding table of the Users entity. As users table already exists (because the User entity is declared before Users), then the table must be named users2.
    • Also, we could return a result with warnings in those cases, as those scenarios are likely to be errors.

Implement TypeScript enhancements

Export

Allow to add export keyword to the generated types. Enabled by default.

Class syntax

Instead of defining interfaces for the entities, generate classes like this:

class User {
    id?: number;
    firstName: string;
    lastName: string;
    age: number;
}

TypeORM

Along with class syntax, allow to generate TypeORM annotations, just like we did for Java and JPA.

Round-trip or reverse engine

Just putting it here as a long term goal --

For erdiagram to be truly helpful, then allowing people to start from existing things will be much appreciated than letting them starting from scratch. I.e.,

A translation tool to translate existing database's DDL to erdiagram's definition text would be super useful for 95+% of cases.

For sure it's not an easy task.

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.