TIL: Previewing SQL generated by Ecto.

Today I Learned that if I want to see the SQL that Ecto will generate I can just pass my query to the to_sq function found in the Ecto.Adapters.SQL module.


query = from "foo", select: [:bar] 
Ecto.Adapters.SQL.to_sql(:all, Repo, query)
#=> {"SELECT a0.\"bar\" FROM \"foo\" AS a0", []}

There is also a short hand method for this on Ecto.Repo

query = from "foo", select: [:bar] 
Repo.to_sql(:all, query)