Skip to main content

Module db_service

Module db_service 

Source
Expand description

Database service: the single owner of the SQLite database.

Every query in the app goes through RusqliteService, which owns the connections and hands work to them — callers never touch a Connection.

  • Writes (execute, insert, transaction, …) are sent as jobs to one dedicated writer thread that owns the read-write connection. SQLite allows one writer at a time anyway; owning it on one thread makes that explicit, keeps connection-wide state (pragmas) out of reach of concurrent callers, and parks no tokio blocking threads on a mutex while writes queue up.
  • Reads (query_*) run on a small pool of read-only connections. The database is in WAL mode, so readers see the last committed state and never wait for the writer — a large catalog-cache transaction no longer stalls library pages, thumbnail lookups or settings reads.

A service built with RusqliteService::new has no reader pool (in-memory databases cannot be shared between connections) and routes reads through the writer, which is the old single-connection behaviour tests rely on.

See docs/architecture/08-database-design.md → “Connection ownership”.

Structs§

Checkout 🔒
Query
Represents a database query that can be executed
ReaderPool 🔒
Read-only connections, checked out one per query. WAL gives each a snapshot of the last commit, so they never wait for the writer.
RusqliteService
Rusqlite-based database service: a cheap, cloneable handle to the writer thread and reader pool. See the module docs.
Transaction
Transaction handle for batching multiple operations
Writer 🔒
The thread that owns the read-write connection. Jobs run one at a time, in the order they were sent; the thread exits when the last service handle (and so the last sender) is dropped.

Enums§

QueryParam
Query parameter types supported by the database

Traits§

DatabaseService
Database service trait - abstraction over database operations

Functions§

convert_params 🔒
Convert QueryParam to rusqlite::types::Value
execute_query 🔒
query_many 🔒
query_one 🔒
query_optional 🔒
run_transaction 🔒

Type Aliases§

DbResult
Database query result type
Job 🔒