Expand description
Kopuz persistence layer (issue #347).
Owns the SQLite schema and all persistence behind a single async Storage
trait. Native targets implement it with sqlx; wasm (not a shipped target)
gets a thin in-memory stub so the build stays green. Everything above this
crate (reactive hooks, UI) is driver-agnostic.
Dependency direction: db sits ABOVE config/reader (it persists their
types), so those crates stay pure model definitions and all save/load lives
here.
Structs§
- Db
- Cheap-
Clonehandle to the active storage backend, shared via Dioxus context. - Import
Report - What a one-shot legacy-JSON import did.
ran == falsemeans it was skipped (already migrated, or no legacy JSON present); the counts are then all zero. - Page
- A window into a list query (for virtual-scrolled big lists).
- Queue
Snapshot - The queue/progress snapshot, reconstructed from the
queue_staterow. The in-memoryPersistedQueueState(in the app crate) maps directly from this. - ReadDb
- Read-only view of the storage backend — the surface the UI gets, so it
cannot reach a write method (those live on
Storage, notReadStore). - Track
Filter - What a windowed track listing selects: which source, how it’s sorted, and
an optional case-insensitive search across title/artist/album. Drives
WHERE/ORDER BYso only the needed rows are materialized. Narrower listings (one album, one artist, one genre, a folder) have dedicatedStoragemethods instead of filter fields — there is deliberately no way to pull a whole source and filter it in memory.
Enums§
- DbError
- Errors surfaced by the storage layer. String-wrapped so the type is identical on native and wasm (sqlx isn’t compiled for wasm).
- Source
- Where a track/playlist/favorite comes from, and what the app is currently sourcing from: the local library, or a specific media server.
- Track
Sort - Sort order for a track listing — maps to an indexed
ORDER BY.
Traits§
- Read
Store - The read side of the persistence API — every query, no mutation. Carried as
a supertrait of
Storage, so anydyn Storageis also adyn ReadStore. - Storage
- The persistence API: every mutation plus admin/dev ops, layered on top of the
read-only
ReadStore. One impl per target (sqlx native / in-mem stub).
Functions§
- config_
dir <config_dir>for kopuz (matches the legacy JSON store location).- default_
db_ path - The on-disk database path:
KOPUZ_DB_PATHoverride, else<config_dir>/kopuz.db(release) orkopuz-debug.db(debug builds, sodx runnever touches real data). - init
- Open the database and apply migrations. Native callers should
block_onthis inmain()before mounting. - peek_
config - Blocking pre-boot read of the config blob — for the few values needed before
the app (and its async runtime/log subscriber) exists: the tracing toggle and
the titlebar mode. Opens the DB read-only without running migrations;
Noneif the DB or blob doesn’t exist yet (first launch). Server/creds fields are NOT hydrated — blob fields only. - release_
db_ path - The RELEASE database path (
kopuz.db), independent of build profile — the debug panel’s “load release DB” source.
Type Aliases§
- Artist
Images - Per-artist images, source-agnostic:
(overrides, photos).overridesare user-set custom photos (always a local path, highest priority);photosare the synced photo per artist as a uniformreader::ArtistImageRef(a server URL or a local path — server wins when both exist), resolved by the cover seam so callers never branch on origin. Both keyed by normalized artist name.