Added posibility to open a `read_uncommitted` transaction on SQLite:
- ### Use case I'd like to be able to see changes made by a connection writer within a connection reader before the writer transaction commits (aka `read_uncommitted` transaction isolation level). ```ruby conn1.transaction do Dog.create(name: 'Fido') conn2.transaction do Dog.find(name: 'Fido') # -> Can't see the dog untill conn1 commits the transaction end end ``` Other adapters in Rails (mysql, postgres) already supports multiple types of isolated db transaction. SQLite doesn't support the 4 main ones but it supports `read_uncommitted` and `serializable` (the default one when opening a transaction) ### Solution This PR allow developers to open a `read_uncommitted` transaction by setting the PRAGMA `read_uncommitted` to true for the duration of the transaction. That PRAGMA can only be enabled if the SQLite connection was established with the [shared-cache mode](https://www.sqlite.org/sharedcache.html) This feature can also benefit the framework and we could potentially get rid of the `setup_shared_connection_pool` inside tests which was a solution in the context of a multi-db app so that the reader can see stuff from the open transaction writer but has some [caveats](https://github.com/rails/rails/issues/37765#event-2828609021). ### Edge case Shared-cache mode can be enabled for in memory database as well, however for backward compatibility reasons, SQLite only allows to set the shared-cache mode if the database name is a URI. It won't allow it if the database name is `:memory`; it has to be changed to `file::memory` instead.
Showing
想要评论请 注册 或 登录