Enumex.Dynamic (Enumex v1.0.0)
View SourceThe module provides a foundation for dynamic enum definitions, based on the enum values that are determined at runtime, allowing you to work with the runtime modifications, while maintaining consistent validation behaviour regardless of the underlying database system.
Covers the Custom Approach pattern,
providing database-level validations across relative databases like SQLite
,
by creating a database relations instead of relying on the native enum types.
See User roles example.
Summary
Main
The type representing a data used in component bindings for static enum definitions.
Defines a dynamic enum with runtime-determined values.
This type represents the configuration options available when defining enum fields,
similar to how timestamps are defined in ecto
.
It provides fine-grained control over field naming, types, and behaviour.
The type representing a field data used in an enum definition with runtime-determined values.
It is generated from enum_field_opts and mirrors the structure of the
ecto
's field/3
DSL by providing a 3-element consisting of name, type, and opts.
The type representing an options for configuring the enum fields.
Components use the field options by, for example by passing them to the field in an Ecto.Schema
.
Main
@type comp_binding_data() :: {:enum_field_opts, [{module(), enum_field_opts()}]} | {:fields, [field()]} | {:plural, atom()}
The type representing a data used in component bindings for static enum definitions.
@spec enum( Enumex.macro_input(module()), Enumex.macro_input(atom()), Enumex.macro_input(enum_field_opts()), Enumex.macro_input(keyword()) ) :: Macro.output()
Defines a dynamic enum with runtime-determined values.
Arguments
module_part
: The module part for the final module nameplural
: The atom representing a plural form of the module nameenum_field_opts
: Options for configuring the enum fields (seeenum_field_opts/0
)opts
: Accepts a code block for an additional enum module code
@type enum_field_opts() :: [ enum_name: atom(), enum_name_opts: field_opts(), enum_name_type: :binary | :binary_id | :string | Enumex.Value.enum_name(), id: atom(), id_opts: field_opts(), id_type: :binary | :binary_id | :string | Enumex.Value.id(), index: atom(), index_opts: field_opts(), index_type: :id | :integer | Enumex.Value.index() ]
This type represents the configuration options available when defining enum fields,
similar to how timestamps are defined in ecto
.
It provides fine-grained control over field naming, types, and behaviour.
Options
The following options are available:
:enum_name
: The atom representing new name for the:enum_name
field:enum_name_opts
: Additional options for the:enum_name
field:enum_name_type
: The type of the:enum_name
field:id
: The atom representing new name for the:id
field:id_opts
: Additional options for the:id
field:id_type
: The type of the:id
field:index
: The atom representing new name for the:index
field:index_opts
: Additional options for the:index
field:index_type
: The type of the:index
field
@type field() :: {atom(), :binary | :binary_id | :id | :integer | :string | Enumex.Value.enum_name() | Enumex.Value.id() | Enumex.Value.index(), field_opts()}
The type representing a field data used in an enum definition with runtime-determined values.
It is generated from enum_field_opts and mirrors the structure of the
ecto
's field/3
DSL by providing a 3-element consisting of name, type, and opts.
@type field_opts() :: [ {:autogenerate, true | {module(), atom(), [any()]}} | {:default, any()} | {:load_in_query, boolean()} | {:primary_key, boolean()} | {:read_after_writes, boolean()} | {:redact, boolean()} | {:skip_default_validation, boolean()} | {:source, atom()} | {:virtual, boolean()} | {:writable, :always | :insert | :never} | {atom(), any()} ]
The type representing an options for configuring the enum fields.
Components use the field options by, for example by passing them to the field in an Ecto.Schema
.