Entity-Relationship Diagram (ERD) builder on top of Yog.
Choreo.ERD models database schemas, including tables, primary/foreign keys,
column definitions, and relations with standard cardinalities.
Node types
:table— represents a database table with structured columns.
Edge types
- Relationships model foreign key links with standard multiplicities:
:one_to_one(exactly-one to exactly-one):one_to_many(exactly-one to zero-or-more):zero_or_one_to_many(zero-or-one to zero-or-more):exactly_one_to_many(exactly-one to one-or-more):many_to_many(zero-or-more to zero-or-more)
Quick Start
erd =
Choreo.ERD.new()
|> Choreo.ERD.add_table(:users, columns: [
%{name: :id, type: :integer, key: :pk},
%{name: :email, type: :varchar}
])
|> Choreo.ERD.add_table(:posts, columns: [
%{name: :id, type: :integer, key: :pk},
%{name: :user_id, type: :integer, key: :fk},
%{name: :title, type: :varchar}
])
|> Choreo.ERD.add_relationship(:users, :posts, cardinality: :one_to_many, label: "writes")
dot = Choreo.ERD.to_dot(erd)
mermaid = Choreo.ERD.to_mermaid(erd)Diagram
| users | ||
| id | integer | [PK] |
| varchar | ||
| posts | ||
| id | integer | [PK] |
| user_id | integer | [FK] |
| title | varchar | |
Summary
Functions
Adds a directed relationship/foreign key edge between two tables in the ERD.
Adds a table to the ERD diagram with structured columns.
Initializes a new, empty ERD.
Returns a theme for the ERD diagram.
Renders the ERD to Graphviz DOT syntax.
Renders the ERD to Mermaid.js native erDiagram syntax.
Types
@type t() :: %Choreo.ERD{ edge_meta: %{optional(Yog.Multi.Graph.edge_id()) => map()}, graph: Yog.Multi.Graph.t(), strict_column_matching: boolean() }
@type table_id() :: Yog.node_id()
Functions
Adds a directed relationship/foreign key edge between two tables in the ERD.
Options
:label(String.t/0) - Visual label/description of the relationship (e.g. 'writes').:cardinality- Required. Multiplicity constraint: :one_to_one, :one_to_many, :zero_or_one_to_many, :exactly_one_to_many, or :many_to_many.:from_column(term/0) - The name of the column in the source table (atom or string).:to_column(term/0) - The name of the column in the destination table (atom or string).
Examples
iex> erd = Choreo.ERD.new()
...> |> Choreo.ERD.add_table(:users, columns: [%{name: :id, type: :integer}])
...> |> Choreo.ERD.add_table(:posts, columns: [%{name: :user_id, type: :integer}])
...> |> Choreo.ERD.add_relationship(:users, :posts, cardinality: :one_to_many)
iex> %Choreo.ERD{} = erd
iex> map_size(erd.graph.edges)
1
Adds a table to the ERD diagram with structured columns.
Options
:label(String.t/0) - Visual label for the table. Defaults to stringified table ID.:columns(term/0) - Required. List of structured columns.
Examples
iex> erd = Choreo.ERD.new()
...> |> Choreo.ERD.add_table(:users, columns: [%{name: :id, type: :integer, key: :pk}])
iex> %Choreo.ERD{} = erd
iex> Map.has_key?(erd.graph.nodes, :users)
true
Initializes a new, empty ERD.
Options
:strict_column_matching- iftrue, validates that any foreign key columns mapped between tables exist and have matching types (default:false).
Examples
iex> erd = Choreo.ERD.new()
iex> %Choreo.ERD{} = erd
iex> erd.strict_column_matching
false
@spec theme( atom(), keyword() ) :: Choreo.Theme.t()
Returns a theme for the ERD diagram.
Examples
iex> theme = Choreo.ERD.theme(:dark)
iex> theme.graph_bgcolor
"#0f172a"
Renders the ERD to Graphviz DOT syntax.
Examples
iex> erd = Choreo.ERD.new() |> Choreo.ERD.add_table(:users, columns: [%{name: :id, type: :integer}])
iex> dot = Choreo.ERD.to_dot(erd)
iex> dot =~ "digraph"
true
Renders the ERD to Mermaid.js native erDiagram syntax.
Examples
iex> erd = Choreo.ERD.new() |> Choreo.ERD.add_table(:users, columns: [%{name: :id, type: :integer}])
iex> Choreo.ERD.to_mermaid(erd) =~ "erDiagram"
true