Skip to main content

koan_core/db/queries/
mod.rs

1mod albums;
2mod artists;
3pub mod auth;
4pub mod batch;
5mod favourites;
6pub mod lyrics;
7pub mod playback_state;
8pub mod radio;
9mod scan_cache;
10mod search;
11pub mod snapshots;
12mod stats;
13pub mod tracks;
14pub mod vectors;
15
16use std::path::PathBuf;
17
18// Re-export all public items so `use queries::*` still works.
19pub use albums::*;
20pub use artists::*;
21pub use batch::*;
22pub use favourites::*;
23pub use lyrics::*;
24pub use playback_state::*;
25pub use radio::*;
26pub use scan_cache::*;
27pub use search::*;
28pub use snapshots::*;
29pub use stats::*;
30pub use tracks::*;
31pub use vectors::*;
32
33// --- Row types ---
34
35#[derive(Debug, Clone)]
36pub struct ArtistRow {
37    pub id: i64,
38    pub name: String,
39    pub sort_name: Option<String>,
40    pub remote_id: Option<String>,
41}
42
43#[derive(Debug, Clone)]
44pub struct AlbumRow {
45    pub id: i64,
46    pub title: String,
47    pub artist_id: i64,
48    pub artist_name: String,
49    pub date: Option<String>,
50    pub total_discs: Option<i32>,
51    pub total_tracks: Option<i32>,
52    pub codec: Option<String>,
53    pub label: Option<String>,
54    pub remote_id: Option<String>,
55}
56
57#[derive(Debug, Clone)]
58pub struct TrackRow {
59    pub id: i64,
60    pub album_id: Option<i64>,
61    pub artist_id: Option<i64>,
62    pub artist_name: String,
63    pub album_artist_name: String,
64    pub album_title: String,
65    pub disc: Option<i32>,
66    pub track_number: Option<i32>,
67    pub title: String,
68    pub duration_ms: Option<i64>,
69    pub path: Option<String>,
70    pub codec: Option<String>,
71    pub sample_rate: Option<i32>,
72    pub bit_depth: Option<i32>,
73    pub channels: Option<i32>,
74    pub bitrate: Option<i32>,
75    pub genre: Option<String>,
76    pub source: String,
77    pub remote_id: Option<String>,
78    pub cached_path: Option<String>,
79}
80
81/// Where to get audio data for playback. Local always wins.
82#[derive(Debug, Clone)]
83pub enum PlaybackSource {
84    Local(PathBuf),
85    Cached(PathBuf),
86    Remote(String),
87}
88
89#[derive(Debug, Clone, Default)]
90pub struct LibraryStats {
91    pub total_tracks: i64,
92    pub local_tracks: i64,
93    pub remote_tracks: i64,
94    pub cached_tracks: i64,
95    pub total_albums: i64,
96    pub total_artists: i64,
97}
98
99/// Metadata for inserting/updating a track.
100#[derive(Debug, Clone)]
101pub struct TrackMeta {
102    pub title: String,
103    pub artist: String,
104    pub album_artist: Option<String>,
105    pub album: String,
106    pub date: Option<String>,
107    pub disc: Option<i32>,
108    pub track_number: Option<i32>,
109    pub genre: Option<String>,
110    pub label: Option<String>,
111    pub duration_ms: Option<i64>,
112    pub codec: Option<String>,
113    pub sample_rate: Option<i32>,
114    pub bit_depth: Option<i32>,
115    pub channels: Option<i32>,
116    pub bitrate: Option<i32>,
117    pub size_bytes: Option<i64>,
118    pub mtime: Option<i64>,
119    pub path: Option<String>,
120    pub source: String,
121    pub remote_id: Option<String>,
122    pub remote_url: Option<String>,
123}
124
125/// Test helper: build a sample TrackMeta for use in tests across sub-modules.
126#[cfg(test)]
127pub fn sample_meta(title: &str, artist: &str, album: &str) -> TrackMeta {
128    TrackMeta {
129        title: title.into(),
130        artist: artist.into(),
131        album_artist: Some(artist.into()),
132        album: album.into(),
133        date: Some("2024".into()),
134        disc: Some(1),
135        track_number: Some(1),
136        genre: Some("Electronic".into()),
137        label: None,
138        duration_ms: Some(240_000),
139        codec: Some("FLAC".into()),
140        sample_rate: Some(44100),
141        bit_depth: Some(16),
142        channels: Some(2),
143        bitrate: Some(1000),
144        size_bytes: Some(30_000_000),
145        mtime: Some(1700000000),
146        path: Some(format!("/music/{}/{}.flac", album, title)),
147        source: "local".into(),
148        remote_id: None,
149        remote_url: None,
150    }
151}