View Source FatEcto.FatHelper (FatEcto v1.0.0)
Provides utility functions for FatEcto, including handling pagination limits, skip values, dynamic binding, and preloading associations.
Summary
Functions
Adds dynamic binding information to a map.
Dynamically preloads associations based on a map.
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.
Merges module-specific options with global and root-level configurations.
Retrieves the primary keys for a given query.
Extracts and validates the skip value from the given parameters.
Retrieves the owner and related association details for a given model and relation.
Removes conflicting order_by
clauses from a query.
Converts a string to an atom.
Converts a string to an existing atom.
Functions
Adds dynamic binding information to a map.
Parameters
map
: The map to process.
Examples
iex> FatEcto.FatHelper.dynamic_binding(%{"$include" => %{"key" => "value"}})
%{"$include" => %{"key" => "value", "$binding" => :first}}
Dynamically preloads associations based on a map.
Parameters
map
: The map containing preloading instructions.
Examples
iex> FatEcto.FatHelper.dynamic_preloading(%{"posts" => %{"$include" => "comments"}})
[posts: :comments]
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, []}
Merges module-specific options with global and root-level configurations.
Parameters
options
: A keyword list of options.module
: The module for which options are being configured.defaults
: Default options to merge.
Examples
iex> FatEcto.FatHelper.get_module_options([max_limit: 50], MyApp.MyContext)
[max_limit: 50, default_limit: 10]
@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, []}
@spec remove_conflicting_order_by(Ecto.Query.t(), any()) :: Ecto.Query.t()
Removes conflicting order_by
clauses from a query.
Parameters
queryable
: The Ecto query.distinct
: The distinct clause.
Examples
iex> FatEcto.FatHelper.remove_conflicting_order_by(from(u in User), nil)
#Ecto.Query<from u in User>
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