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_list() View Source
preload_list() :: [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 type suffix() View Source
suffix() :: atom() | {atom(), atom()}

Link to this section Functions

Link to this macro __using__(opts) View Source (macro)
__using__(options()) :: no_return()

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, an s is appended to name the list_<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 in list, get and get! 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 in create_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]