Experimental Livebook-friendly DSL for sketching entity-relationship diagrams.
This Lab DSL compiles to the stable, pipe-first Choreo.ERD builders and
returns an ordinary %Choreo.ERD{}. Tables can be declared as compact column
blocks, while relationship edges expose ERD cardinalities as domain vocabulary.
Examples
iex> import Choreo.Lab.DSL.ERD
...> schema = erd do
...> users = table("users") do
...> pk :id, :integer
...> field :email, :varchar, comment: "unique email"
...> end
...>
...> posts = table("posts") do
...> pk :id, :integer
...> fk :user_id, :integer
...> field :title, :varchar
...> end
...>
...> one_to_many users ~> posts, "writes", from: :id, to: :user_id
...> end
iex> schema.graph.nodes[:users].columns |> Enum.map(& &1[:name])
[:id, :email]
iex> [meta] = Map.values(schema.edge_meta)
iex> {meta.cardinality, meta.label, meta.from_column, meta.to_column}
{:one_to_many, "writes", :id, :user_id}Relationship edges can use typed constructors, generic edge, or pipe
modifiers:
one_to_many users ~> posts, "writes"
has_many users ~> posts, "writes"
edge users ~> posts, one_to_many: "writes"
users ~> posts |> one_to_many("writes") |> columns(:id, :user_id)The generic ~> form defaults to :one_to_many, which matches the most common
parent-table-to-child-table sketching direction.
Summary
Functions
Builds a %Choreo.ERD{} from a compact Lab DSL block.
Returns the vocabulary supported by the ERD DSL.
Compatibility alias for taxonomy/0.
Types
@type relationship_decl() :: %{ from: Yog.node_id(), to: Yog.node_id(), opts: keyword() }
@type table_decl() :: %{id: Yog.node_id(), opts: keyword()}
Functions
Builds a %Choreo.ERD{} from a compact Lab DSL block.
@spec taxonomy() :: %{ tables: [atom()], columns: [atom()], edges: [atom()], modifiers: [atom()], options: [atom()] }
Returns the vocabulary supported by the ERD DSL.
This is meant as a lightweight Livebook discovery helper when autocomplete is not enough.
iex> taxonomy = Choreo.Lab.DSL.ERD.taxonomy()
iex> :table in taxonomy.tables
true
iex> :pk in taxonomy.columns
true
iex> :one_to_many in taxonomy.edges
true
@spec verbs() :: %{ tables: [atom()], columns: [atom()], edges: [atom()], modifiers: [atom()], options: [atom()] }
Compatibility alias for taxonomy/0.