Just put use Ecto.Shortcuts
in your Ecto model or call it in the model method in the web/web.ex
of your Phoenix app.
defmodule PhoenixApp.User do
use PhoenixApp.Web, :model
use Ecto.Shortcuts
end
You can now call get/1
, all/0
, delete/1
, etc on the model directly:
User.all
# instead of PhoenixApp.Repo.all(User)
User.get(2)
# instead of PhoenixApp.Repo.get(User, 2)
- Is the naming scheme correct? (i.e. is
Ecto.Shortcuts
a good name?) - Is doing this a good idea?
- Are there any anti-patterns in the code?
- Am I using macros correctly?
- What should I keep in mind while publishing this as a hex package?