EctoUtils.Repo (ecto_utils v0.1.0)
Utility module containing functions which aim to augment modules that use Ecto.Repo
Link to this section Summary
Functions
Allows you to execute any EctoUtils.Repo function in the module that use-es this
macro.
Returns true if the given paramter is an Elixir module that use-es Ecto.Schema
or is a struct derived from a module that use-es Ecto.Schema
Given a struct derived from a module that use-es Ecto.Schema, returns the list
of currently preloaded associations for said schema.
Link to this section Functions
Allows you to execute any EctoUtils.Repo function in the module that use-es this
macro.
This is useful for centralizing Repo functions in your app's own repo module, rather
than you needing to manually call EctoUtils.Repo functions yourself.
Usage:
defmodule MyApp.Repo do
use Ecto.Repo, ...
use EctoUtils.Repo
end
MyApp.Repo.is_schema(Date.utc_today())
> false is_schema(module)
Specs
Returns true if the given paramter is an Elixir module that use-es Ecto.Schema
or is a struct derived from a module that use-es Ecto.Schema
list_preloads(record)
Specs
Given a struct derived from a module that use-es Ecto.Schema, returns the list
of currently preloaded associations for said schema.
This can be useful when used in conjunction with Repo.reload/2 to refetch a given
struct from the database while also reloading all preloads:
user = %MyApp.User{orgs: [...]}
preloads = MyApp.Repo.list_preloads(user)
user
|> MyApp.Repo.reload()
|> MyApp.Repo.preload(preloads)