-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapter config for default_transaction_mode: IMMEDIATE
#153
Comments
It doesn't bother me if someone adds it. Right now I've settled on using: defmodule MyApp.Repo do
use Ecto.Repo, adapter: Ecto.Adapters.SQLite3, otp_app: :my_app
def immediate_transaction(fun_or_multi) do
transaction(fun_or_multi, mode: :immediate)
end
end I have a few cases in my personal project where I want deferred and opt into immediate mode for transactions. This has to do with multiple processes reading from the database at the same time. In my use case, I wanted as low as possible blocks to reads as I can because this is a heavy read application with low writes. If you want to add the option, you are more than welcome to try it out. Although you will need to do that change in Keep in mind, we are going through some reworking of the underlying adapter sqlite implementation and the ecto adapter to better consolidate responsibilities. You'll need to add to the def handle_begin(options, %{transaction_status: transaction_status, state.default_transaction_mode: state.default_transaction_mode} = state) do
mode = Keyword.get(options, :mode) || default_transaction_mode || :deferred
# ...
end Then you'll probably need to shim that default mode into defp do_connect(database, options) do
# ... with block ....
state = %__MODULE__{
default_transaction_mode: Keyword.get(options, :default_transaction_mode, :deferred)
}
# ...
end You'll then need to update the |
Thanks for the tips. I'll pick it up in a week. |
Personally though, I still think having the helper function defined on the I have this in my application's
And use it like BUT, with the changes I suggested above for the default transaction mode it won't break my application and is a reasonable ask. |
@warmwaffles I create a PR for exqlite. When it's merged, I'll add one for the current repo with some more documentation. |
@warmwaffles And the follow-up PR with docs: #155 |
Awesome. Thank you for knocking this out. |
I am trying to use sqlite in a project and have noticed that there is no option to set a
IMMEDIATE
transaction mode globally.This has been brought up before here: #151 and the conclusion was to have the responsibility on the caller.
I want to raise the question again to have a configuration on the adapter level and maybe even make it default.
Here are 2 convincing sources:
The author did extensive testing with Rails and concluded that it is not viable to have
DEFERRED
in a typical Rails application. And to me a typical Rails application has the same usage pattern as a Phoenix application.Aaron Francis is a well known database expert and his sqlite course is amazing. Here are some quotes:
To summarise:
IMMEDIATE
transaction mode makes the most sense for a web application. Passing manuallymode: :immediate
is not a good experience.Main question: Are the maintainers open to a config on adapter level? In Rails the config is called
default_transaction_mode: IMMEDIATE
, we could do the same.I am happy to do the work, with some pointers where to start best.
The text was updated successfully, but these errors were encountered: