LazyContext v0.1.5-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>/0get_<example>/1get_<example>!/1create_<example>/1create_<example>!/1create_or_update_<example>/1create_or_update_<example>!/1update_<example>/2update_<example>!/2delete_<example>/1delete_<example>!/1change_<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
:schemaa module that implemented Ecto.Schema (use Ecto.Schema):suffixsuffix to construct function names. If an atom is provided, ansis appended to name thelist_<examples>/0function. Alternatively, a 2 atom tuple can be provided to specify the plural (e.g.{:person, :people}):preloadsa list of fields to preload inlist,getandget!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_keyslist of keys used to identify an updateable item increate_or_update_<example>. Defaults to [:id]:repothe 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]