View Source Mobilizon.Storage.Page (Mobilizon v5.0.0-beta.1)
Module for pagination of queries.
Summary
Functions
Returns a Page struct for a query.
Stream chunks of results from the given queryable.
Add limit and offset to the query.
Types
@type t(structure) :: %Mobilizon.Storage.Page{elements: [structure], total: integer()}
Functions
Returns a Page struct for a query.
field
is use to define the field that will be used for the count aggregate, which should be the same as the field used for order_by
See https://stackoverflow.com/q/12693089/10204399
@spec chunk(Ecto.Queryable.t(), integer()) :: Stream.t()
Stream chunks of results from the given queryable.
Unlike Repo.stream, this function does not keep a long running transaction open. Hence, consistency is not guarenteed in the presence of rows being deleted or sort criteria changing.
Example
Ecto.Query.from(u in Users, order_by: [asc: :created_at]) |> Repo.chunk(100) |> Stream.map(&process_batch_of_users) |> Stream.run()
Source
@spec paginate(Ecto.Queryable.t() | struct(), integer() | nil, integer() | nil) :: Ecto.Query.t()
Add limit and offset to the query.