How can I see the raw SQL generated for an Ecto.Query?

You can use Ecto.Adapters.SQL.to_sql/3: iex> Ecto.Adapters.SQL.to_sql(:all, Repo, Post) {“SELECT p.id, p.title, p.inserted_at, p.created_at FROM posts as p”, []} This function is also available under the repository with name to_sql if you’re using a SQL based adapter: iex> Repo.to_sql(:all, Post) {“SELECT p.id, p.title, p.inserted_at, p.created_at FROM posts as p”, []} The query can be any struct … Read more

How to rollback, reset, or drop Ecto test database?

You can access the test database by using MIX_ENV=test followed by a command such as mix do ecto.drop, mix ecto.reset or mix ecto.rollback. In this particular case, I used: MIX_ENV=test mix ecto.reset If your application has multiple repos (DBs), you’ll want to specify a specific repo to avoid applying the operation to all repos. For … Read more

How to use raw sql with ecto Repo

On Ecto 2.0 (beta) with Postgres, you can use Ecto.Adapters.SQL.query() (current docs, 2.0-beta2 docs) to execute arbitrary SQL; in addition to a list of the rows themselves (“rows“), it happens to return a list of column names (“columns“). In the below example, I run a custom query with no parameters, convert the result’s column names … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)