Merlive

Entity diagrams

An entity is a box that lists its attributes under its name, and a relationship ends in how many. Held to the same measure, and to the rows each box lists and what each link ends in.

Declared with erDiagram. Of 48 features Mermaid documents for an entity diagram, 38 drawn as written, 10 drawn less something. See all 48 drawn both ways, or draw one yourself.

Mermaid
Entity relationship diagram, as Mermaid draws it
Merlive
Entity relationship diagram, as Merlive draws it

What is read

A block that starts erDiagram is read into the same boxes and links as a flowchart, so everything else on this page holds for it: the rules, the design, Merlive's own lines. An entity is a box that lists its attributes under its name; a relationship is a link that says, at each end, how many.

WrittenRead as
ORDER, ORDER-LINE, "Purchase order"An entity: a box. In Merlive's own lines it is named with _ for whatever an id cannot hold (%% note ORDER_LINE: …, %% main: Purchase_order>ORDER_LINE)
s[Supplier], a["Supplier account"]An alias, shown in place of the name
ORDER { … }Its attributes as a table under its name: a row for each, a column for types, one for names and one for keys when any has a key, ruled into cells with every second row shaded. Declared twice, the two lists are joined
int number, string(40) reference, string[] barcodes, decimal(10,2) price, date? paidAn attribute: its type, then its name, shown as written
int number PK, string code PK, FK, string *codeIts keys, after its name. A star before a name is a primary key, and is shown as PK
string reference "Only 40 characters"Its comment, kept out of the table so the boxes stay narrow: it is in the note on its entity, after whatever note its author wrote (reference: Only 40 characters)
SUPPLIER ||--o{ ORDER : receivesA relationship: a link from the first entity to the second, with its words. They may be in quotes, empty, or left out
||, |o o|, }| |{, }o o{How many, at the end it is written at: one; none or one; one or more; any number. Either spelling at either end
only one, 1, zero or one, one or zero, one or more, one or many, 1+, many(1), zero or more, zero or many, 0+, many(0)The same, in words
--, toA relationship that gives the second entity its identity: a solid line
.., optionally toOne that does not: a dotted line
SUPPLIER }o..o| SUPPLIER : "buys from"A relationship from an entity to itself: a small loop beside it
subgraph Buying … end, subgraph "Paying up", subgraph pay ["Paying up"], Buying ||--|| Paying : …A group, one inside another if written so, as in a flowchart; a relationship with a group goes to where it starts or from where it ends
classDef late stroke:#c62828, class ORDER,INVOICE late, ORDER:::lateKinds, as in a flowchart. A box is of one kind: of several classes (late,held), the first
style ORDER stroke:#c00,stroke-width:4px,stroke-dasharray: 5 5What the style says of its outline, as in a flowchart
direction TBThe way it runs. An entity diagram is drawn top to bottom for now: any other direction is read past, and said once. A group's own direction across it is followed, as in a flowchart
title: in front matter, accTitle, accDescr, %% commentsAs in a flowchart

Not read, each named in a note, line when met: attributes written on the line that opens them (ORDER { int number }), and a line between the braces that is not a type and a name. A name written as Markdown ("A **firm** order") is drawn as plain words.

Feature by feature

Every feature Mermaid’s own pages set out for an entity diagram, each with a sample of it in the corpus. A sample is drawn when every box, link and word it has is read and every rule passes. Drawn, less something is the same with one thing known to be missing, named beside it.

FeatureResultWhat is missing
An entity diagram: entities, and the relationships between themDrawn
An entity with no relationshipsDrawn
Attributes: a type and a name eachDrawn
An entity declared twice, its attributes joinedDrawn
An entity declared with no attributes between its bracesDrawn
A name with a hyphen in itDrawn
A name with spaces, in quotesDrawn
Names, words and attributes in other alphabetsDrawn
A name written as MarkdownDrawn, less somethingBold and italic are drawn as plain words
An alias shown in place of the nameDrawn
Zero or one, at either endDrawn
Exactly one, at either endDrawn
Zero or more, at either endDrawn
One or more, at either endDrawn
A mark written the other way round for its endDrawn
How many, written in wordsDrawn
How many, in the short forms: 1, 1+, 0+, many(0), many(1)Drawn
A relationship that identifies: a solid lineDrawn
A relationship that does not identify: a dotted lineDrawn
Identifying or not, written in wordsDrawn
A relationship's words, in quotesDrawn
A relationship with empty wordsDrawn
A relationship written with no spacesDrawn
A relationship from an entity to itselfDrawn
Keys: primary, foreign and uniqueDrawn
Several keys on one attributeDrawn
A star before a name, for a primary keyDrawn
A comment on an attributeDrawn, less somethingA comment is not in its row: it is in the note on its entity, which a reader sees on picking the box
Types with a length, a list, and two numbersDrawn
A type that may be missingDrawn
Direction: top to bottomDrawn
Direction: left to rightDrawn, less somethingDrawn top to bottom: boxes of different heights are only placed that way yet
A group, named by one wordDrawn
A group named by words in quotesDrawn
A group with an id and a titleDrawn
A group inside a groupDrawn
Relationships to and from groupsDrawn, less somethingA relationship with a group is drawn to where the group starts, or from where it ends
A group with a direction of its ownDrawn, less somethingThe group's own direction is read past; it runs the way the rest does
An entity styled on its ownDrawn, less somethingIts outline is broken, heavy and red as written, in the design's own red; its fill is the design's
Several entities styled in one lineDrawn, less somethingTheir outlines are heavy and blue as written, in the design's own blue
A class made and given to entitiesDrawn
Several classes given at onceDrawn, less somethingA box is of one kind: of several classes, the first is the one it is
A class given with :::Drawn
A class given with ::: in a relationshipDrawn
A default class for every entityDrawn, less somethingThe default class is read past: the look is the design's
A title and settings in front matterDrawn, less somethingMermaid's own settings are read past: the look and the placement are Merlive's
A title and a description for readers who cannot see itDrawn
Comments, on lines of their own, between statements and between attributesDrawn

Written from skills/merlive/reference.md in the repository, so the two cannot disagree.

Before: Class diagramsNext: Requirement diagrams