# `Choreo.Lab.DSL.ERD`
[🔗](https://github.com/code-shoily/choreo/blob/v0.14.1/lib/choreo/lab/dsl/erd.ex#L1)

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.

# `relationship_decl`

```elixir
@type relationship_decl() :: %{
  from: Yog.node_id(),
  to: Yog.node_id(),
  opts: keyword()
}
```

# `table_decl`

```elixir
@type table_decl() :: %{id: Yog.node_id(), opts: keyword()}
```

# `column`

# `columns`

# `edge`

# `entity`

# `erd`
*macro* 

Builds a `%Choreo.ERD{}` from a compact Lab DSL block.

# `erd`
*macro* 

# `exactly_one_to_many`

# `field`

# `fk`

# `foreign_key`

# `from`

# `from_column`

# `has_and_belongs_to_many`

# `has_at_least_one`

# `has_many`

# `has_one`

# `many_to_many`

# `maybe_has_many`

# `on`

# `one_to_many`

# `one_to_one`

# `pk`

# `primary_key`

# `table`

# `taxonomy`

```elixir
@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

# `to`

# `to_column`

# `verbs`

```elixir
@spec verbs() :: %{
  tables: [atom()],
  columns: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}
```

Compatibility alias for `taxonomy/0`.

# `zero_or_one_to_many`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
