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

Support the project

Silver Sponsors

Support the project

Bronze Sponsors

Support the project

Setting Up EctoDbg

After adding {:ecto_dbg, "~> 0.1.0"} 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
use EctoDbg
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
use EctoDbg, level: :info
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)

By default the use EctoDbg macro will inject the debug functions into your repo module for only the :test and :devMix.env() environments. If you would like to override this default behaviour, you can do that by providing the :only option (this value should be a subset of the environments that you passed in your mix.exs file):

defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
use EctoDbg, only: :dev
end

Attribution