Aurora. Uix. Filter
(Aurora UIX v0.1.4-rc.6)
Copy Markdown
Provides a structured filter representation for query conditions with support for multiple comparison operators, value storage, and type-safe construction.
Key Features
- Multiple comparison operators (equality, range, set membership)
- Type-safe construction with enforced keys
- Flexible value storage in list format
- Support for enabled/disabled state management
Supported Operators
| Symbol | Atom | Description |
|---|---|---|
= | :eq | Equal to |
> | :gt | Greater than |
< | :lt | Less than |
≥ | :ge | Greater than or equal |
≤ | :le | Less than or equal |
b | :between | Between two values |
i | :in | In a set of values |
Examples
# Creating a basic equality filter
filter = Aurora.Uix.Filter.new(:user_id)
%Aurora.Uix.Filter{key: :user_id, condition: :eq, enabled?: false, values: [nil]}
# Creating with custom attributes
filter = Aurora.Uix.Filter.new(%{
key: :age,
condition: :gt,
values: [18],
enabled?: true
})
%Aurora.Uix.Filter{key: :age, condition: :gt, enabled?: true, values: [18]}
# Creating from string key
Aurora.Uix.Filter.new("status")
%Aurora.Uix.Filter{key: :status, condition: :eq, enabled?: false, values: [nil]}Constraints
:keymust be an atom (enforced at struct creation):conditionmust be one of the supported operators:valuesare always stored in a list, even for single-value conditions:enabled?defaults tofalsefor new filters
Summary
Functions
Updates an existing filter with new attributes.
Returns the supported condition mappings.
Creates a new filter struct from various input types.
Types
Functions
Updates an existing filter with new attributes.
Parameters
filter(t()) - Existing filter struct to modifyattrs(map()) - Map of attributes to update
Returns
t()- Updated filter struct with merged attributes
Examples
filter = Aurora.Uix.Filter.new(:status)
Aurora.Uix.Filter.change(filter, %{condition: :in, values: ["active", "pending"]})
%Aurora.Uix.Filter{
key: :status,
condition: :in,
enabled?: false,
values: ["active", "pending"]
}
Returns the supported condition mappings.
Each tuple contains a human-readable symbol and its corresponding internal atom representation used in filter conditions.
Returns
list({binary(), atom()})- Ordered list of condition mappings
Examples
Aurora.Uix.Filter.conditions()
[
{"=", :eq},
{">", :gt},
{"<", :lt},
{"≥", :ge},
{"≤", :le},
{"b", :between},
{"i", :in}
]
Creates a new filter struct from various input types.
Parameters
attrs(map() | atom() | binary()) - Filter configuration where:- Map must contain
:key(atom) and:condition(atom) - Atom creates equality filter for that key
- String converts to atom and creates equality filter
- Map must contain
Returns
t()- New filter struct with provided or default values
Examples
# From map with all attributes
Aurora.Uix.Filter.new(%{key: :price, condition: :between, values: [10, 50]})
%Aurora.Uix.Filter{key: :price, condition: :between, enabled?: false, values: [10, 50]}
# From atom key (defaults to equality)
Aurora.Uix.Filter.new(:category)
%Aurora.Uix.Filter{key: :category, condition: :eq, enabled?: false, values: [nil]}
# From string key
Aurora.Uix.Filter.new("created_at")
%Aurora.Uix.Filter{key: :created_at, condition: :eq, enabled?: false, values: [nil]}