ecto_resource v0.1.0 EctoResource
This module represents the generic CRUD functionality that is boilerplate within Phoenix context files. It provides a DSL to easily generate the basic functions for a schema. This allows the context to focus on interesting, atypical implementations rather than the redundent, drifting crud functions.
defmodule MyContext do use EctoResource
using_repo(Repo) do
resource(MySchema)
end end
This will generate the functions:
MyContext.change_my_schema(changable)
- changable object to generate changeset for
MyContext.create_my_schema(attributes)
- attributes
MyContext.delete_my_schema(deletable)
- deletable: Schema object to delete
MyContext.get_my_schema(id, options)
- id: id field for the schema value to be queried for
options:
- preloads
MyContext.all_my_schema(options)
options:
- preloads
- order_by
MyContext.paginate_my_schema(pagination, options)
- pagination
options:
- preloads
MyContext.update_my_schema(updatable, attributes)
- updatable: Schema object to update
- attributes
There are also introspection functions to understand what is generated by the macro
MyContext.__resource__(:resources)
- A listing of the defined resources and their generated functions
Link to this section Summary
Link to this section Functions
all(repo, schema, options \\ [])
all(Ecto.Repo.t(), module(), term()) :: [Ecto.Schema.t()]
change(schema, changable)
change(module(), Ecto.Schema.t()) :: Ecto.Changeset.t()
create(repo, schema, attributes)
create(Ecto.Repo.t(), module(), map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
delete(repo, deletable)
delete(Ecto.Repo.t(), Ecto.Schema.t()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
get(repo, schema, id, options \\ [])
get(Ecto.Repo.t(), module(), term(), term()) :: Ecto.Schema.t() | nil
paginate(repo, schema, pagination, options \\ [])
paginate(Ecto.Repo.t(), module(), Engine.Pagination.t(), term()) :: Scrivener.Page.t()
underscore_module_name(module)
update(repo, schema, updateable, attributes)
update(Ecto.Repo.t(), module(), Ecto.Schema.t(), map()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}