I want to display data from my database through Ecto in a custom mix task. How can I get Ecto relay in my task (or run it)?
I tried something like this, but this did not work:
defmodule Mix.Tasks.Users.List do use Mix.Task use Mix.Config use Ecto.Repo, otp_app: :app @shortdoc "List active users" @moduledoc """ List active users """ def run(_) do import Ecto.Query, only: [from: 1] Mix.shell.info "=== Active users ===" query = from u in "users" sync = all(query) Enum.each(users, fn(s) -> IO.puts(u.name) end) end end
This will give me the following result when I run mix users.list:
** (ArgumentError) repo Mix.Tasks.Users.List is not started, please ensure it is part of your supervision tree lib/ecto/query/planner.ex:64: Ecto.Query.Planner.query_lookup/5 lib/ecto/query/planner.ex:48: Ecto.Query.Planner.query_with_cache/6 lib/ecto/repo/queryable.ex:119: Ecto.Repo.Queryable.execute/5
Any idea or other way to solve this problem?
elixir phoenix-framework mix
Mika andrianarijaona
source share