FatEcto.SharedHelper (FatEcto v1.2.0)
View SourceProvides 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
@spec filterable_opt_to_map(maybe_improper_list() | any()) :: maybe_improper_list() | map()
@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]
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
Parses an integer from a string or returns the integer if already an integer.
Returns the parsed integer on success or nil
on failure.
Converts a string to an atom.
Parameters
str
: The string to convert.
Examples
iex> FatEcto.SharedHelper.string_to_atom("example")
:example
Converts a string to an existing atom.
Parameters
str
: The string to convert.
Examples
iex> FatEcto.SharedHelper.string_to_existing_atom("example")
:example