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

dynamic_binding(map)

@spec dynamic_binding(map()) :: map()

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}}

dynamic_preloading(map)

@spec dynamic_preloading(map()) :: [{atom(), atom() | [atom()]}]

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]

fat_ecto_reserve_field?(value)

@spec fat_ecto_reserve_field?(any()) :: boolean()

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

get_limit_bounds(options)

@spec get_limit_bounds(nil | keyword() | map()) :: {integer(), integer()}

Returns the maximum and default limit values based on the provided options.

Parameters

  • options: A keyword list or map containing max_limit and default_limit.

Examples

iex> FatEcto.FatHelper.get_limit_bounds(max_limit: 50, default_limit: 10)
{50, 10}

get_limit_value(params, options \\ [])

@spec get_limit_value(
  keyword(),
  nil | keyword() | map()
) :: {integer(), keyword()}

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 containing max_limit and default_limit.

Examples

iex> FatEcto.FatHelper.get_limit_value([limit: 15], max_limit: 50, default_limit: 10)
{15, []}

get_module_options(options, module, defaults \\ [])

@spec get_module_options(keyword(), module(), keyword()) :: keyword()

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]

get_primary_keys(query)

@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]

get_skip_value(params)

@spec get_skip_value(keyword()) :: {integer(), keyword()}

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, []}

remove_conflicting_order_by(queryable, arg2)

@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>

string_to_atom(str)

@spec string_to_atom(String.t()) :: atom()

Converts a string to an atom.

Parameters

  • str: The string to convert.

Examples

iex> FatEcto.FatHelper.string_to_atom("example")
:example

string_to_existing_atom(str)

@spec string_to_existing_atom(String.t()) :: atom()

Converts a string to an existing atom.

Parameters

  • str: The string to convert.

Examples

iex> FatEcto.FatHelper.string_to_existing_atom("example")
:example