FatEcto.FatHelper (FatEcto v1.1.0)

View Source

Provides 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

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

implements_behaviour?(module, behaviour)

@spec implements_behaviour?(module(), module()) :: boolean()

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

string_to_atom(already_atom)

@spec string_to_atom(String.t() | atom()) :: 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(already_atom)

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

Converts a string to an existing atom.

Parameters

  • str: The string to convert.

Examples

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