AshDiagram.Data.EntityRelationship (AshDiagram v0.2.1)
View SourceProvides functions to create Entity-Relationship Diagrams for Ash applications.
This module generates ERDs showing Ash resources as entities with their attributes, calculations, aggregates, and relationships with proper cardinality indicators.
Ash-Specific Features
- Resource Entities: Ash resources displayed as ERD entities
- Attributes: Resource attributes, calculations, and aggregates
- Relationships: Ash relationships with cardinality derived from relationship types
- Visibility: Respects Ash
public?settings for attributes and relationships - Extensions: Automatically includes diagrams from Ash extensions
Summary
Types
Configuration option for entity-relationship diagram generation.
List of configuration options for entity-relationship diagram generation.
Functions
Generates an entity-relationship diagram for the given OTP applications.
Generates an entity-relationship diagram for the given Ash domains.
Generates an entity-relationship diagram for the given Ash resources.
Types
@type option() :: {:name, :full | :short} | {:show_private?, boolean()}
Configuration option for entity-relationship diagram generation.
Available options:
{:name, :full | :short}- How to display resource names.:fullshows complete module names,:shortshows shortened names with common prefixes removed{:show_private?, boolean()}- Whether to include private attributes, calculations, aggregates, and relationships in the diagram
@type options() :: [option()]
List of configuration options for entity-relationship diagram generation.
Functions
@spec for_applications(applications :: [Application.app()], options :: options()) :: AshDiagram.EntityRelationship.t()
Generates an entity-relationship diagram for the given OTP applications.
Creates an ERD showing all Ash resources from the specified OTP applications, including their attributes, calculations, aggregates, and relationships with cardinality indicators.
Parameters
applications- List of OTP application names (e.g.,[:my_app, :other_app])options- Keyword list of options, seeoption/0for available options
Examples
# Generate ERD for a single application
AshDiagram.Data.EntityRelationship.for_applications([:my_app])
# Generate diagram with full module names
AshDiagram.Data.EntityRelationship.for_applications([:my_app], name: :full)
# Include private attributes and relationships
AshDiagram.Data.EntityRelationship.for_applications([:my_app], show_private?: true)
@spec for_domains(domains :: [Ash.Domain.t()], options :: options()) :: AshDiagram.EntityRelationship.t()
Generates an entity-relationship diagram for the given Ash domains.
Creates an ERD showing all resources within the specified domains, including their attributes, calculations, aggregates, and relationships with cardinality indicators.
Parameters
domains- List of Ash domain modules (e.g.,[MyApp.Blog, MyApp.Accounts])options- Keyword list of options, seeoption/0for available options
Examples
# Generate ERD for specific domains
AshDiagram.Data.EntityRelationship.for_domains([MyApp.Blog, MyApp.Accounts])
# Generate diagram with short names only
AshDiagram.Data.EntityRelationship.for_domains([MyApp.Blog], name: :short)
@spec for_resources(resources :: [Ash.Resource.t()], options :: options()) :: AshDiagram.EntityRelationship.t()
Generates an entity-relationship diagram for the given Ash resources.
Creates an ERD showing the specified resources with:
- Entity boxes containing attributes, calculations, and aggregates
- Relationship lines with cardinality indicators (1, 0..1, , 0..)
- Proper ERD notation for identifying and non-identifying relationships
Parameters
resources- List of Ash resource modules (e.g.,[MyApp.User, MyApp.Post])options- Keyword list of options, seeoption/0for available options
Examples
# Generate ERD for specific resources
AshDiagram.Data.EntityRelationship.for_resources([MyApp.User, MyApp.Post])
# Use full module names and show private fields
AshDiagram.Data.EntityRelationship.for_resources(
[MyApp.User, MyApp.Post],
name: :full,
show_private?: true
)
# Generate diagram with only public elements
AshDiagram.Data.EntityRelationship.for_resources([MyApp.User], show_private?: false)