Alembic v4.0.0 Alembic.Fetch.Sorts View Source

Fetching Data > Sorting

Link to this section Summary

Types

t()

An order list of Alembic.Fetch.Sort.t

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

Link to this type params() View Source
params() :: %{}

An order list of Alembic.Fetch.Sort.t

Link to this section Functions

Link to this function from_params(params) View Source
from_params(params()) :: t()

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"
      }
    }
  }
]
Link to this function from_string(comma_seperated_sorts) View Source
from_string(String.t()) :: t()

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"

Link to this function to_string(sorts) View Source
to_string(t()) :: String.t()

Converts a list of Alembic.Fetch.Sort.t back to a string