Skip to main content

read_pool

Function read_pool 

Source
pub fn read_pool() -> Result<&'static AnyPool, AppError>
Expand description

The pool QueryBuilder’s own read methods (get/first/count) resolve through - a dedicated, engine-enforced read-only SQLite connection pool (?mode=ro, see connect’s own doc comment) that lets reads proceed concurrently with each other and with the single writer connection, instead of serializing behind it the way they do through pool alone.

Checks POOL_OVERRIDE first, identically to pool - this is what keeps larust_testing::test_transaction’s isolated-pool override and test_db() working with no test-infra changes at all. Falls back to pool itself when no dedicated reader pool exists: MySQL/Postgres (their own multi-connection pool already handles concurrent reads and writes via row-level locking, so no second pool is ever built for them), or SQLite before connect has run (giving the same “not connected yet” error pool() would give in that case).

Don’t hold a transaction open against this pool - a long-held read snapshot delays SQLite’s own WAL checkpoint for every other reader and writer sharing the file.