mix ecto.query (Ecto SQL v3.15.0)

Copy Markdown View Source

Runs the given query against the repository.

The query is evaluated as Elixir code after importing Ecto.Query. If a local .iex.exs file exists, only aliases from the file are made available to the query.

Unless --to-sql or --explain is given, the query runs inside a read-only transaction.

Examples

$ mix ecto.query "from p in Post, where: p.published"
$ mix ecto.query -r Custom.Repo "from p in Post, limit: 10"
$ mix ecto.query --to-sql "from p in Post, where: p.published"
$ mix ecto.query --explain "from p in Post, where: p.published"

Command line options

  • -r, --repo - the repo to query
  • --limit - limits the number of printed entries. Defaults to 100.
  • --to-sql - prints the generated SQL and parameters instead of running the query
  • --explain - prints the query plan instead of running the query