SimpleSchemaContext.Schema (simple_schema_context v0.1.0)
View SourceCore module that provides a set of standard context functions for Phoenix schemas.
When used, it automatically imports all the necessary Ecto modules and defines a complete set of CRUD operations for the schema:
list/0
andlist/2
- List all records with optional filteringlist_by_ids/2
- Fetch records by IDsfetch/2
- Get a single record with error handlingget!/2
- Get a single record or raise if not foundcreate/2
- Create a new recordupdate/3
- Update an existing recordchange/3
- Create a changeset for a recorddelete/2
- Delete a record
## Options
When using this module, you must provide the following options:
:repo
- The Ecto.Repo module to use for database operations
## Example
defmodule MyApp.Blog.Post do
use SimpleSchemaContext.Schema, repo: MyApp.Repo
schema "posts" do
field :title, :string
field :body, :text
timestamps()
end
def changeset(post, attrs) do
post
|> cast(attrs, [:title, :body])
|> validate_required([:title, :body])
end
end