FatEcto.SharedHelper (FatEcto v1.2.0)

View Source

Provides utility functions for FatEcto, including handling pagination limits, skip values, dynamic binding, and preloading associations.

Summary

Functions

Retrieves the primary keys for a given query.

Checks if a module implements the given behaviour by inspecting its __info__/1 metadata.

Parses an integer from a string or returns the integer if already an integer.

Converts a string to an atom.

Converts a string to an existing atom.

Functions

filterable_opt_to_map(list)

@spec filterable_opt_to_map(maybe_improper_list() | any()) ::
  maybe_improper_list() | map()

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.SharedHelper.get_primary_keys(from(u in User))
[:id]

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

keyword_list_to_map(list)

@spec keyword_list_to_map(keyword() | map()) :: map()

parse_integer!(int_str)

@spec parse_integer!(any()) :: integer() | nil

Parses an integer from a string or returns the integer if already an integer.

Returns the parsed integer on success or nil on failure.

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.SharedHelper.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.SharedHelper.string_to_existing_atom("example")
:example