EctoUtils.Repo (ecto_utils v0.2.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.
Executes the given closure in a transaction; returning its returns, but ensuring that the transaction was rolled back in the process.
Given a struct derived from a module that use
-es Ecto.Schema
, returns the list
of currently preloaded associations for said schema.
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
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.schema?(Date.utc_today())
> false
dry_run(repo, closure)
Specs
Executes the given closure in a transaction; returning its returns, but ensuring that the transaction was rolled back in the process.
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.preloads(user)
user
|> MyApp.Repo.reload()
|> MyApp.Repo.preload(preloads)
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