View Source Ecspanse.Entity (ECSpanse v0.9.0)

Entities are only identifiers. An entity exists only if it holds at least one component. The entities per se are not persisted.

Entities are represented as a struct with id as the only field.

Examples

  %Ecspanse.Entity{id: "cfa1ad89-44b6-4d1f-8590-186354be9158"}

Summary

Types

An entity_spec is the definition required to create an entity.

t()

The entity struct.

Types

@type entity_spec() :: {Ecspanse.Entity, opts :: keyword()}

An entity_spec is the definition required to create an entity.

Options

  • :id - a custom unique ID for the entity (binary). If not provided, a random UUID will be generated.
  • :components - a list of Ecspanse.Component.component_spec/0 to be added to the entity.
  • :children A list of Ecspanse.Entity.t/0 to be added as children to the entity. Children entities should already exist.
  • :parents A list of Ecspanse.Entity.t/0 to be added as parents to the entity. Parent entities should already exist.

Note

At least one of the :components, :children or :parents options must be provided, otherwise the entity cannot be persisted.

Entity ID

The entity IDs must be unique. Attention when providing the :id option as part of the entity_spec. If the provided ID is not unique, spwaning entities will raise an error.

@type id() :: binary()
@type t() :: %Ecspanse.Entity{id: id()}

The entity struct.

Functions

@spec fetch(id()) :: {:ok, t()} | {:error, :not_found}

See Ecspanse.Query.fetch_entity/1.