Alembic v4.0.0 Alembic.Fetch.Sorts View Source
Link to this section Summary
Functions
Extracts t
from "sort"
in params
Breaks the sort
into list of Alembic.Fetch.Sort.t
Separates each sort in "sort"
Converts a list of Alembic.Fetch.Sort.t
back to a string
Link to this section Types
An order list
of Alembic.Fetch.Sort.t
Link to this section Functions
Extracts t
from "sort"
in params
params
without "sort"
will have no sorts
iex> Alembic.Fetch.Sorts.from_params(%{})
[]
params
with "sort"
will have the value of "sort"
broken into t
iex> Alembic.Fetch.Sorts.from_params(
...> %{
...> "sort" => "-inserted-at,author.name,-comments.author.posts.inserted-at"
...> }
...> )
[
%Alembic.Fetch.Sort{attribute: "inserted-at", direction: :descending, relationship: nil},
%Alembic.Fetch.Sort{attribute: "name", direction: :ascending, relationship: "author"},
%Alembic.Fetch.Sort{
attribute: "inserted-at",
direction: :descending,
relationship: %{
"comments" => %{
"author" => "posts"
}
}
}
]
Breaks the sort
into list of Alembic.Fetch.Sort.t
An empty String will have no sorts
iex> Alembic.Fetch.Sorts.from_string("")
[]
A single attribute name will have the default direction of :ascending
and no :relationship
iex> Alembic.Fetch.Sorts.from_string("inserted-at")
[%Alembic.Fetch.Sort{attribute: "inserted-at", direction: :ascending, relationship: nil}]
An attribute name with -
before will have the direction reversed to :descending
.
iex> Alembic.Fetch.Sorts.from_string("-inserted-at")
[%Alembic.Fetch.Sort{attribute: "inserted-at", direction: :descending, relationship: nil}]
In a dot-seperated sequence of names, the final name is the attribute name and all preceding names are a relationship
path in the same format as Alembic.RelationshipPath
iex> Alembic.Fetch.Sorts.from_string("author.name,-comments.author.posts.inserted-at")
[
%Alembic.Fetch.Sort{attribute: "name", direction: :ascending, relationship: "author"},
%Alembic.Fetch.Sort{
attribute: "inserted-at",
direction: :descending,
relationship: %{
"comments" => %{
"author" => "posts"
}
}
}
]
Separates each sort in "sort"
Converts a list of Alembic.Fetch.Sort.t
back to a string