LazyContext v0.1.4-dev LazyContext View Source
LazyContext is a library that provides useful functions for accessing and creating data around an Ecto Schema.
Generated functions:
list_<examples>/0
get_<example>/1
get_<example>!/1
create_<example>/1
create_<example>!/1
create_or_update_<example>/1
create_or_update_<example>!/1
update_<example>/2
update_<example>!/2
delete_<example>/1
delete_<example>!/1
change_<example>/2
see LazyContext.Examples.Users
for example generated functions with docs
Link to this section Summary
Functions
Inserts functions around an Ecto Schema. All inserted functions are overridable
Link to this section Types
Link to this type
options()
View Source
options() :: [ schema: module(), suffix: suffix(), preloads: preload_list() | preload_map(), create_or_update_uniqueness_keys: [atom()] ]
Link to this type
preload_map()
View Source
preload_map() :: %{ optional(:list) => preload_list(), optional(:get) => preload_list(), optional(:get!) => preload_list() }
Link to this section Functions
Inserts functions around an Ecto Schema. All inserted functions are overridable
Options
:schema
a module that implemented Ecto.Schema (use Ecto.Schema
):suffix
suffix to construct function names. If an atom is provided, ans
is appended to name thelist_<examples>/0
function. Alternatively, a 2 atom tuple can be provided to specify the plural (e.g.{:person, :people}
):preloads
a list of fields to preload inlist
,get
andget!
functions. Alternatively a map of function prefix to preload map can be provided to specify which function should preload which fields.:create_or_update_uniqueness_keys
list of keys used to identify an updateable item increate_or_update_<example>
. Defaults to [:id]:repo
the Ecto Repo used to access the data - can be ommitted if repo was provided via config
Examples
use LazyContext,
schema: User,
suffix: :user
use LazyContext,
schema: Dog,
suffix: :dog,
preloads: %{
get: [:owner]
get!: [:owner]
},
create_or_update_uniqueness_keys: [:colour, :cuteness]