hotshot_query_service/sqlite_options.rs
1//! Shared SQLite connection defaults.
2//!
3//! Used by both the embedded-db variant of this crate and by external clients (e.g. the light
4//! client) that build their own pool. Keeping the pragma choices in one place ensures every
5//! SQLite database in the workspace runs with the same journaling, locking, and vacuum settings.
6
7use std::time::Duration;
8
9use sqlx::sqlite::{SqliteAutoVacuum, SqliteConnectOptions, SqliteJournalMode};
10
11/// Default [`SqliteConnectOptions`] for SQLite databases in this workspace.
12///
13/// WAL journaling is the load-bearing choice: under the default rollback journal, any writer
14/// holds an exclusive lock that blocks readers on other connections, which produces spurious
15/// `SQLITE_BUSY` ("database is locked") errors under concurrent access. WAL lets readers and
16/// the single writer proceed in parallel.
17///
18/// Callers add `.filename(...)` (or use `:memory:`) on top.
19pub fn sqlite_options() -> SqliteConnectOptions {
20 SqliteConnectOptions::default()
21 .journal_mode(SqliteJournalMode::Wal)
22 .busy_timeout(Duration::from_secs(30))
23 .auto_vacuum(SqliteAutoVacuum::Incremental)
24 .create_if_missing(true)
25}