For some query in Controller of Phoenix, there\'re two plans for me
Plan 1:
defmodule Demo.UserController do
# ...
def index do
# This is jus
You should keep your Repo calls inside your controller. If your logic is complicated then you should consider moving the logic out into its own service module.
You should treat your model functions as pure (free from side effects) so they should only act on data. So for example you could have:
def alphabetical(query)
order_by(query, [u], u.name)
end
But you should not have:
def alphabetical(query)
order_by(query, [u], u.name)
|> Repo.all
end
This is because queries are purely data, the call to Repo.all
has side effects (going off to the database) so it belongs in your controller.