Ark.EctoCursor.OrderBy (ark v0.14.0)

Copy Markdown View Source

An Ecto.Type for the sort order of an Ark.EctoCursor.

In Elixir, the sort order is a non-empty list of {direction, field} tuples such as [asc: :inserted_at, asc: :id]. It is stored as a list of string pairs such as [["asc", "inserted_at"], ["asc", "id"]].

Casting accepts both forms, along with the shorthand syntax of the :order_by option of Ark.EctoCursor.new/1. Loading a stored sort order converts field names with String.to_existing_atom/1.

Summary

Functions

Normalizes a sort order to a list of {direction, field} tuples.

Callback implementation for Ecto.Type.equal?/2.

Types

t()

@type t() :: [{:asc | :desc, atom()}, ...]

Functions

cast!(order_by)

Normalizes a sort order to a list of {direction, field} tuples.

Field names without a direction sort in ascending order.

iex> Ark.EctoCursor.OrderBy.cast!([:score, desc: :id])
[asc: :score, desc: :id]

A single field name is a shorthand for a list of one field.

iex> Ark.EctoCursor.OrderBy.cast!(:id)
[asc: :id]

Accepts a field name, or a non-empty list of field names and {direction, field} tuples where the direction is :asc or :desc. Raises an ArgumentError for any other value and for duplicate fields.

equal?(term1, term2)

Callback implementation for Ecto.Type.equal?/2.