Alembic v3.3.0 Alembic.Fetch.Sorts

Fetching Data > Sorting

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

Types

params()
params() :: %{}

An order list of Alembic.Fetch.Sort.t

Functions

from_params(params)
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"
      }
    }
  }
]
from_string(comma_seperated_sorts)
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"
      }
    }
  }
]
sort_separator()

Separates each sort in "sort"

to_string(sorts)
to_string(t) :: String.t

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