EctoDbg Elixir LogoEctoDbg title

Easily debug and pretty print your Ecto SQL queries

Hex.pmGitHub Workflow Status (master)Coveralls master branchSupport the project


Contents

Installation

Available in Hex, the package can be installed by adding ecto_dbg to your list of dependencies in mix.exs:

def deps do
  [
    {:ecto_dbg, "~> 0.1.0", only: [:dev, :test]}
  ]
end

Documentation can be found at https://hexdocs.pm/ecto_dbg.

Supporting EctoDbg

If you rely on this library help you debug your Ecto queries, it would much appreciated if you can give back to the project in order to help ensure its continued development.

Checkout my GitHub Sponsorship page if you want to help out!

Gold Sponsors

<img align="center" height="175" src="guides/images/your_logo_here.png" alt="Support the project">

Silver Sponsors

<img align="center" height="150" src="guides/images/your_logo_here.png" alt="Support the project">

Bronze Sponsors

<img align="center" height="125" src="guides/images/your_logo_here.png" alt="Support the project">

Setting Up EctoDbg

After adding {:ecto_dbg, "~> 0.1.0", only: [:test, :dev]} in your mix.exs file and running mix deps.get, open your repo.ex file and add the following contents:

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres

  unless Mix.env() == :prod do
    use EctoDbg
  end
end

You can also pass configuration options to EctoDbg if you so chose like so (see the EctoDbg module docs for more information):

defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres

  unless Mix.env() == :prod do
    use EctoDbg, level: :info
  end
end

With that in place, any time that you want to inspect a query that is executed by Ecto, all you need to do is the following

query = from user in User

Repo.all_and_log(query)

Attribution