FatEcto.FatHelper (FatEcto v1.1.0)
View SourceProvides utility functions for FatEcto, including handling pagination limits, skip values, dynamic binding, and preloading associations.
Summary
Functions
Determines if a value is a reserved field in FatEcto.
Returns the maximum and default limit values based on the provided options.
Extracts and validates the limit value from the given parameters.
Retrieves the primary keys for a given query.
Extracts and validates the skip value from the given parameters.
Checks if a module implements the given behaviour by inspecting its __info__/1
metadata.
Converts a string to an atom.
Converts a string to an existing atom.
Functions
Determines if a value is a reserved field in FatEcto.
Parameters
value
: The value to check.
Examples
iex> FatEcto.FatHelper.fat_ecto_reserve_field?("$INCLUDE")
true
Returns the maximum and default limit values based on the provided options.
Parameters
options
: A keyword list or map containingmax_limit
anddefault_limit
.
Examples
iex> FatEcto.FatHelper.get_limit_bounds(max_limit: 50, default_limit: 10)
{50, 10}
Extracts and validates the limit value from the given parameters.
Parameters
params
: A keyword list containing the:limit
value.options
: A keyword list or map containingmax_limit
anddefault_limit
.
Examples
iex> FatEcto.FatHelper.get_limit_value([limit: 15], max_limit: 50, default_limit: 10)
{15, []}
@spec get_primary_keys(Ecto.Query.t()) :: [atom()] | nil
Retrieves the primary keys for a given query.
Parameters
query
: The Ecto query.
Examples
iex> FatEcto.FatHelper.get_primary_keys(from(u in User))
[:id]
Extracts and validates the skip value from the given parameters.
Parameters
params
: A keyword list containing the:skip
value.
Examples
iex> FatEcto.FatHelper.get_skip_value(skip: 20)
{20, []}
Checks if a module implements the given behaviour by inspecting its __info__/1
metadata.
Parameters
module
: The module to check.behaviour
: The behaviour to validate against.
Examples
iex> implements_behaviour?(MyApp.Repo, Ecto.Repo)
true
iex> implements_behaviour?(NotARepo, Ecto.Repo)
false
Converts a string to an atom.
Parameters
str
: The string to convert.
Examples
iex> FatEcto.FatHelper.string_to_atom("example")
:example
Converts a string to an existing atom.
Parameters
str
: The string to convert.
Examples
iex> FatEcto.FatHelper.string_to_existing_atom("example")
:example