Add adapter level read-only transaction support#741
Open
cdvx wants to merge 2 commits into
Open
Conversation
- 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.
e221a67 to
c31b6eb
Compare
v0idpwn
reviewed
Jul 13, 2026
|
|
||
| @impl true | ||
| def read_only_transaction(conn, opts, fun) do | ||
| {:ok, _} = query(conn, "SET TRANSACTION READ ONLY", [], log: nil) |
Member
There was a problem hiding this comment.
Don't we log the BEGIN/END in the transaction? If yes, we should log this too.
|
|
||
| @impl true | ||
| def read_only_transaction(_conn, _opts, _fun) do | ||
| raise ArgumentError, "read-only transactions are not supported by Ecto.Adapters.Tds" |
Member
There was a problem hiding this comment.
Can maybe not implement the callback and get the very same error
|
|
||
| @impl true | ||
| def read_only_transaction(conn, opts, fun) do | ||
| {:ok, _} = query(conn, "SET TRANSACTION READ ONLY", [], log: nil) |
Member
There was a problem hiding this comment.
I guess this is more involved, but some databases allow you to set the transaction to read-only in the begin statement. This would be one less query round trip, if it's achievable.
Member
There was a problem hiding this comment.
I think this is a good starting point and we should move it to the adapters next.
- 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
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.queryuse the shared transaction option instead of adapter-specific transaction SQL itself.Closes #736.