BoxTurtle.Schema (BoxTurtle v0.1.0)

Copy Markdown View Source

A convention-driven data-access layer for Ecto schemas.

For a schema MyApp.Blog.Post, define two sibling modules and let them be the only code that touches the Repo:

defmodule MyApp.Blog.Post.Query do
  use BoxTurtle.Schema.Query, repo: MyApp.Repo, default_sort: [desc: :inserted_at]
end

defmodule MyApp.Blog.Post.Change do
  use BoxTurtle.Schema.Change, repo: MyApp.Repo
end

alias MyApp.Blog.Post

{:ok, post} = Post.Change.create(%{title: "Hello"})   # uses Post.changeset/2
[^post] = Post.Query.list!(filters: [title: "Hello"])
1 = Post.Query.count!()

See the Schema guide for a complete walkthrough.