Skip to content

Commit

Permalink
add docs and example
Browse files Browse the repository at this point in the history
  • Loading branch information
ehne committed Jun 26, 2020
1 parent 10f694b commit 28cd3e2
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ env
test.json
ERDotOutput.dot
.pypirc
imageFile.png
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
128 changes: 124 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,134 @@
</a>
</p>

>
## About
> Creates Entity Relationship Diagrams from JSON code.
## Installation
to install ERDot:

```pip install ERDot```

you may also need to [install graphvis](https://graphviz.org/download/) to be able to create images of the dot files generated.

## CLI Usage
```
Usage: erdot [OPTIONS]
Options:
-i, --inputFile TEXT The input ERDJSON file (.json) [required]
-o, --outputFile TEXT The graphvis dot file to write to (.dot) (default: ERDotOutput.dot)
--help Show this message and exit.
```

Note that after generating the .dot file, you will still need to output it to your desired format using graphvis. An example of how to do this:

```bash
erdot -i inputFile.erd.json

dot ERDotOutput.dot -Tpng -o imageFile.png
```

## ERDJSON format:
```json
{
"tables":{
...
},
"relations":[
...
],
"rankAdjustments":"...",
"label":"..."
}
```

Every single one of these sections are required, however, if you dont need that specific feature (for example label or rankAdjustments), just leave the value blank

### table:
Each table inside of the table section of the ERDJSON document is formated like this:

```json
"TableName": {
"*PrimaryKey": "Int(10)",
"+ForeignKey": "Int(10)",
"RandomData": "Char(70)"
}
```

the general idea is that the key is the column name, and the value is the type.

you will also notice the `*` and `+` next to the column names, these indicate primary and foriegn keys respectively. You can combine two of these together into a primary foreign key, just by putting both a `*` and a `+` next to the name.

### relations:
each element in the relations array of the ERDJSON document is formatted like this:

```json
"TableOne:PrimaryKey 1--* TableTwo:ForeignKey"
```

There are three elements that make up the relation string, (1) the left hand side, (2) the cardinality indicator, and (3) the right hand side.

#### Left and Right hand side:
The sides of the relation string consist of two elements, separated by a `:`. the text before the `:` indicates what table it is in, and the text after the `:` indicates what specific column it should use to link. (note how you dont include the `+` or `*` in the specific column text).

#### Cardinality indicator:
Each relationship must have two of these cardinalities in the indicator, separated by `--`:

```
Cardinality Syntax
0 or 1 ?
exactly 1 1
0 or more *
1 or more +
```

So for example, the following defines a relationship between Person's PersonID primary key and BirthPlace's PersonID foreign key that reads "every person has exactly one birth place, linked together using PersonID":

```python
Person:PersonID *--1 BirthPlace:PersonID
```

### rankAdjustments
applies graphvis' rank adjustments to adjust where the tables appear in the final image. (note that it is only one string)

```js
{ rank=min; TableOne Tabletwo }; // sets TableOne and TableTwo to be in the minimum rank (left)
{ rank=same; TableThree TableFour }; // sets TableThree and TableFour to be in the same rank
{ rank=max; TableFive }; // sets TableFive to be in the maximum rank (right)
```

### Label
a string that sets what label will be drawn on top of the ERD, think of it like the title of the ERD.

## Example ERDJSON:
```json
{
"tables":{
"Person":{
"*name":"char()",
"height":"int()",
"weight":"int()",
"birthDate":"date()",
"birthPlaceID":"int()"
},
"BirthPlace":{
"*id":"int()",
"birthCity":"char()",
"birthState":"char()",
"birthCountry":"char()"
}
},
"relations":[
"Person:birthPlaceID *--1 BirthPlace:id"
],
"rankAdjustments":"",
"label":""
}
```

## Usage
which then creates this image:

<img alt="logo" src="https://github.com/ehne/ERDot/raw/master/example/example.png" align="center"/>


## Author
Expand Down
54 changes: 54 additions & 0 deletions example/example.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

digraph G {
graph [
nodesep=0.5;
rankdir="LR";
cencentrate=true;
splines="spline";
fontname="Helvetica";
pad="0.2,0.2",
label="",

];

node [shape=plain, fontname="Helvetica"];
edge [
dir=both,
fontsize=12,
arrowsize=0.9,
penwidth=1.0,
labelangle=32,
labeldistance=1.8,
fontname="Helvetica"
];

Person [ label=<
<table border="0" cellborder="1" cellspacing="0" >
<tr><td><i>Person</i></td></tr>
<tr><td port="name" align="left" cellpadding="5">PK name <font color="grey60">char()</font></td></tr>
<tr><td port="height" align="left" cellpadding="5">height <font color="grey60">int()</font></td></tr>
<tr><td port="weight" align="left" cellpadding="5">weight <font color="grey60">int()</font></td></tr>
<tr><td port="birthDate" align="left" cellpadding="5">birthDate <font color="grey60">date()</font></td></tr>
<tr><td port="birthPlaceID" align="left" cellpadding="5">birthPlaceID <font color="grey60">int()</font></td></tr>
</table>>];
BirthPlace [ label=<
<table border="0" cellborder="1" cellspacing="0" >
<tr><td><i>BirthPlace</i></td></tr>
<tr><td port="id" align="left" cellpadding="5">PK id <font color="grey60">int()</font></td></tr>
<tr><td port="birthCity" align="left" cellpadding="5">birthCity <font color="grey60">char()</font></td></tr>
<tr><td port="birthState" align="left" cellpadding="5">birthState <font color="grey60">char()</font></td></tr>
<tr><td port="birthCountry" align="left" cellpadding="5">birthCountry <font color="grey60">char()</font></td></tr>
</table>>];


Person:birthPlaceID->BirthPlace:id [
arrowhead=noneotee,

arrowtail=ocrow,
];





}
23 changes: 23 additions & 0 deletions example/example.erd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"tables":{
"Person":{
"*name":"char()",
"height":"int()",
"weight":"int()",
"birthDate":"date()",
"birthPlaceID":"int()"
},
"BirthPlace":{
"*id":"int()",
"birthCity":"char()",
"birthState":"char()",
"birthCountry":"char()"
}
},
"relations":[
"Person:birthPlaceID *--1 BirthPlace:id"
],
"rankAdjustments":"",
"label":""
}

Binary file added example/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 28cd3e2

Please sign in to comment.