title: How to get data from Ecto in a custom mix task
body: <p>I want to display data from my DB through Ecto in a custom mix task. How can I get the Ecto repo in my task (or start it)?</p>
  
  <p>I tried something like this but it didn't work:</p>
  
  <pre><code>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) -&gt; IO.puts(u.name) end)
    end
  
  end
  </code></pre>
  
  <p>This will give me the following output when I launch mix users.list: </p>
  
  <pre><code>** (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
  </code></pre>
  
  <p>Any idea or other way to solve this problem?</p>