Current section

Files

Jump to
pageantry lib pageantry field.ex
Raw

lib/pageantry/field.ex

defmodule Pageantry.Field do
@moduledoc """
Field definition for sorting/filtering.
## Fields
* `field`
: Field name (in schema), eg `:inserted_at`.
* `relation`
: If field is not directly in schema, how the field is related.
* `repo`
: HACK this can be removed when `Pageantry.Page.build_subquery_condition/3`
no longer needs it.
* `sort`
: True if sortable (defaults to true).
* `filter`
: Filter type:
* `:false`: Cannot be used as filter.
* `:equal`: Filter value must be exactly equal to field value.
* `:like`: Filter value matched to field value with SQL `LIKE`.
* `:boolean`: Filter and field values casted to boolean and matched.
For cases where you want to filter on whether an optional field has been set
(eg "has_address=yes").
* `all`
: True if included in special `:ALL` filter (defaults to true).
"""
alias Ecto.Repo
alias Pageantry.FieldRelation
@enforce_keys [:field]
defstruct [:field, :relation, :repo, sort: true, filter: :equal, all: true]
@type filter :: false | :equal | :like | :boolean
@type t :: %__MODULE__{
field: atom,
relation: FieldRelation.t(),
repo: Repo.t(),
sort: boolean,
filter: filter,
all: boolean
}
end