https://github.com/edrdo/dbdia
Diagram generator for Entity-Relationship models and relational schemas.
https://github.com/edrdo/dbdia
antlr colab database diagram er graphviz java python schema
Last synced: 6 months ago
JSON representation
Diagram generator for Entity-Relationship models and relational schemas.
- Host: GitHub
- URL: https://github.com/edrdo/dbdia
- Owner: edrdo
- License: apache-2.0
- Created: 2020-04-13T01:45:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-09T18:47:51.000Z (over 2 years ago)
- Last Synced: 2024-11-10T22:40:36.818Z (12 months ago)
- Topics: antlr, colab, database, diagram, er, graphviz, java, python, schema
- Language: Java
- Homepage:
- Size: 182 KB
- Stars: 26
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://github.com/edrdo/dbdia/blob/master/LICENSE.txt)
[](https://github.com/edrdo/dbdia/releases)
[](https://github.com/edrdo/dbdia/actions/workflows/ci.yml)
# dbdia
__Author: [Eduardo R. B. Marques](https://github.com/edrdo)__
__dbdia__ is open-source software under the terms of the __[Apache License 2.0](https://github.com/edrdo/dbdia/blob/master/LICENSE.txt)__.
## Summary
__dbdia__ is a diagram generator for database __Entity-Relationship (ER)__ models
and __relational schemas__.
Diagrams are expressed using a domain-specific language
that is translated to image format (PNG, PDF, SVG, ...) using the __dot__ tool from __[Graphviz](https://graphviz.org)__ .
The visual syntax employed by __dbdia__ in ER and relational diagrams mostly follows the conventions of the __[Fundamentals of Database Systems, 7th edition](https://www.pearson.com/us/higher-education/program/Elmasri-Fundamentals-of-Database-Systems-7th-Edition/PGM189052.html)__ textbook by Ramez Elmasri and Shamkant B. Navathe.
## Run dbdia online using a Colab notebook
[](https://colab.research.google.com/github/edrdo/dbdia/blob/master/src/main/colab/dbdia.ipynb)
## DSL used for ER models and relational schemas
Check [__here__](/DSL.md) for a description of the DSL used by dbdia.
## Examples
Check the __examples__ directory in this repository or in the dbdia release archive.
The examples can be also be tested directly in the Colab notebook.


### Entity definitions
```
EntityName
(
_ KeyField _,
OptionalField ?,
. DerivedField .,
{ MultiValueField },
CompositeField ( SubField1, { SubField2 }, SubField3 ?, . SubField4 .),
{ ComplexField(SubField1, SubField2(SubField21, SubField22)) }
)
```

### Relationship definitions
```
EntityA ( ) // with no attributes (just for convenience)
EntityB ( ) // you can in any case ommit attributes in diagrams
EntityC ( ) // using the 'rel' diagram type generation
// Relationship: Rel1
// Entities involved: EntityA and EntityB
// Cardinality: 1 to N
// Participation: partial for EntityA, total for EntityB
// Relationship attributes: none
EntityA --- 1 --- < Rel1 > === N === EntityB
// Relationship: Rel2
// Entities involved: EntityA and EntityB
// Cardinality: M to N
// Participation: partial for both entities
// Relationship attributes: none
EntityA --- M --- < Rel2 > --- N --- EntityB
// Relationship: Rel3
// Entities involved: EntityA and EntityC
// Cardinality: 1 to 1
// Participation: total for EntityA, partial for EntityC
// Relationship attributes: Rattr1, { RAttr2 } as shown.
EntityA === 1 === < Rel3( RAttr1, { RAttr2 } )> --- 1 --- EntityC
```

### Relational schema definitions
```
table A
(
_ PrimaryKey _,
PlainField,
OptionalField ?,
ForeignKey1 --> A.PrimaryKey,
ForeignKey2 --> B.PrimaryKey
)
// Type info is optional - this table has type annotations per each field
// Any identifier is accepted for the type designation.
table B
(
_ PrimaryKey _ int,
PlainField varchar
)
```

## Download, install, and use
### Dependencies
- A Java runtime environment, version 8 or higher.
- [Graphviz](https://graphviz.org)
The following should work with recent versions of Ubuntu:
```
sudo apt install default-jre
sudo apt intall graphviz
```
### Install
- Download the ZIP of the latest release [here](https://github.com/edrdo/dbdia/releases).
- Unzip the release archive to some folder ____
- The __dbdia__ script (for Linux/MacOS/POSIX) and the __dbdia.bat__
variant for Windows can be found in __/bin__.
It may be convenient to add __/bin__ to your __PATH__ environment.
### Usage
```
dbdia [-option1=value1 ... -optionk=valuek] inputFile outputFile
```
__Diagram types__
- `er`: full ER diagram including entities, entity attributes, and relationships;
- `ent`: ER diagram including entities and their attributes only;
- `rel`: ER diagram excluding entity attributes;
- `sch`: relational schema diagram.
__Options__
- Type `dbdia help` for a list of options.
## Compiling from scratch
Requirements:
- Java JDK (OracleJDK or OpenJDK) for Java 8 or higher
- Maven 3.x
Commands:
```
git clone git@github.com:edrdo/dbdia.git
cd dbdia
mvn package
```