FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add adapter level read-only transaction support by cdvx · Pull Request #741 · elixir-ecto/ecto_sql · GitHub

Add adapter level read-only transaction support - #741

Merged
josevalim merged 3 commits into
elixir-ecto:masterfrom
cdvx:add-read-only-opt-to-transaction
Jul 18, 2026
Merged

Add adapter level read-only transaction support#741
josevalim merged 3 commits into
elixir-ecto:masterfrom
cdvx:add-read-only-opt-to-transaction

Conversation

cdvx commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Adds repo.transaction(read_only: true) support for SQL adapters by moving the read-only transaction handling into adapter-level connection callbacks.

This lets mix ecto.query use the shared transaction option instead of adapter-specific transaction SQL itself.

Closes #736.

- Add adapter-level read_only_transaction callbacks for SQL adapters
- Update mix ecto.query to use the transaction read_only opt instead of  adapter-specific transaction SQL.
cdvx force-pushed the add-read-only-opt-to-transaction branch from e221a67 to c31b6eb Compare July 13, 2026 09:06
Comment thread lib/ecto/adapters/myxql/connection.ex Outdated
Comment thread lib/ecto/adapters/tds/connection.ex Outdated
Comment thread lib/ecto/adapters/myxql/connection.ex Outdated
- Log SET TRANSACTION READ ONLY through the transaction logger
- Remove the TDS read_only_transaction callback so Ecto.Adapters.SQL raises the unsupported adapter error
cdvx requested review from josevalim and v0idpwn July 13, 2026 17:19
Comment thread lib/ecto/adapters/sql.ex Outdated

## Connection helpers

defp read_only_transaction(adapter_meta, connection, opts, callback) do

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hrm.... what happens if we are already inside a transaction, which is not read-only, and we call this? One option is to detect and raise but that means additional bookkeeping. And because the database themselves are very different when it comes to this functionality, the API is awkward.

I am thinking we don't add this functionality as part of the official repo or transaction API. We just add this exclusively to the adapter and call the adapter directly in mix ecto.query?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good point 🤔, let me adjust to this

- Move read-only query execution out of the Repo.transaction API
- Call the SQL adapter hook directly from mix ecto.query.
cdvx requested a review from josevalim July 15, 2026 08:28

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM! Any other remarks @v0idpwn?

Copy link
Copy Markdown
Member

Merging, any other remarks can be deal with later! Thank youy @cdvx!!!!

Btw, do you think it is also worth adding a --explain flag to mix ecto.query? In this case we don't have anything to inspect, we just print the results on terminal.

josevalim merged commit f761250 into elixir-ecto:master Jul 18, 2026
9 of 10 checks passed

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

v0idpwn commented Jul 20, 2026

Copy link
Copy Markdown
Member

Looks great to me too, sorry about the lag

cdvx commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Merging, any other remarks can be deal with later! Thank youy @cdvx!!!!

Btw, do you think it is also worth adding a --explain flag to mix ecto.query? In this case we don't have anything to inspect, we just print the results on terminal.

This sounds good!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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 read_only: true option to transaction

3 participants


Back | FazBrowse Home | New Git URL