FatEcto v0.5.0 FatEcto.Sample.Pagination View Source

Link to this section Summary

Link to this section Functions

Link to this function

count_records(count_query, repo)

View Source

Paginate the records.

Parameters

  • query - Ecto Queryable that represents your schema name, table name or query.
  • params - limit and skip values.

Examples

    iex> query_opts = %{
    ...>    "$select" => %{
    ...>     "$fields" => ["name", "location", "rating"]
    ...>    },
    ...>   "$where" => %{
    ...>      "name" => "%John%",
    ...>      "location" => nil,
    ...>      "rating" => "$not_null",
    ...>      "total_staff" => %{"$between" => [1, 3]}
    ...>    }
    ...>  }
    iex> query = Elixir.MyApp.Query.build!(FatEcto.FatHospital, query_opts)
    iex> result = Elixir.FatEcto.Sample.Pagination.paginate(query, [limit: 10, skip: 0])
    iex>  %{count_query: count_query, data_query: data_query, limit: limit, skip: skip} = result
    iex> limit
    10
    iex> skip
    0
    iex> count_query
    #Ecto.Query<from f0 in FatEcto.FatHospital, where: f0.total_staff > ^1 and f0.total_staff < ^3 and (not(is_nil(f0.rating)) and (f0.name == ^"%John%" and (is_nil(f0.location) and ^true))), distinct: true>
    iex> data_query
    #Ecto.Query<from f0 in FatEcto.FatHospital, where: f0.total_staff > ^1 and f0.total_staff < ^3 and (not(is_nil(f0.rating)) and (f0.name == ^"%John%" and (is_nil(f0.location) and ^true))), limit: ^10, offset: ^0, select: map(f0, [:name, :location, :rating])>
Link to this function

paginate_get_records(query, params, repo)

View Source
Link to this function

paginator(query, params, repo)

View Source