Skip to content

Add mix ecto.query task#733

Merged
josevalim merged 4 commits into
elixir-ecto:masterfrom
cdvx:add-mix-ecto-query-task
Jun 26, 2026
Merged

Add mix ecto.query task#733
josevalim merged 4 commits into
elixir-ecto:masterfrom
cdvx:add-mix-ecto-query-task

Conversation

@cdvx

@cdvx cdvx commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Closes elixir-ecto/ecto#4719

Implements a read-only query Mix task run through the selected or default repo. Accepts --sql to render generated SQL and params for the passed query without running it, otherwise returns schema level output. Raises is adapter does not support read only transactions.

Closes elixir-ecto/ecto#4719

Implements a read-only query Mix task run through the selected or default
repo. Accepts --sql to render generated SQL and params for the passed query
without running it, otherwise returns schema level output.
Raises is adapter does not support read only transactions.
Comment thread lib/mix/tasks/ecto.query.ex Outdated
Comment thread lib/mix/tasks/ecto.query.ex Outdated
Comment thread test/mix/tasks/ecto.query_test.exs Outdated
Comment thread test/mix/tasks/ecto.query_test.exs Outdated
Comment thread lib/mix/tasks/ecto.query.ex Outdated

@josevalim josevalim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I dropped what is likely the final batch of comments and we should be good!

cdvx and others added 2 commits June 23, 2026 11:21
Co-authored-by: José Valim <jose.valim@gmail.com>
- clean up tests
- use inspect_fun opt instead of overriding global state for inspect
- copy implementation of inspect/4 Inspect.Map protocol instead of calling private API directly
- parse only aliases from .iex.exs
@cdvx

cdvx commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the delay, I dropped what is likely the final batch of comments and we should be good!

No worries at all, thanks for the thorough review! I’ve addressed the comments: .iex.exs now only contributes aliases, inspection uses inspect_fun, and the test setup is cleaned up.

@cdvx cdvx requested a review from josevalim June 23, 2026 11:57
Comment thread lib/mix/tasks/ecto.query.ex Outdated

defp do_read_only_transaction(Ecto.Adapters.MyXQL, repo, fun) do
repo.checkout(fn ->
repo.query!("START TRANSACTION READ ONLY", [], log: false)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would move this to the adapter behaviour itself, so SQLite3 and other databases can implement, but it can be done in another pull request. Something like repo.transaction(read_only: true).

@josevalim josevalim merged commit 5e45b43 into elixir-ecto:master Jun 26, 2026
10 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add mix ecto.query

3 participants