Skip to main content

videre_api/
stats.rs

1//! Facade over videre-core's library-wide aggregate stats. Thin wrapper so
2//! callers go through one shared `Error`/`Result` type like every other
3//! videre-api operation. (`videre mcp` may adopt this later, once its own
4//! JSON contract question is resolved. See the Pass A design doc.)
5
6use crate::error::Result;
7use rusqlite::Connection;
8pub use videre_core::library_stats::LibraryStats;
9
10pub fn library_stats(conn: &Connection) -> Result<LibraryStats> {
11    Ok(videre_core::library_stats::compute(conn)?)
12}
13
14#[cfg(test)]
15mod tests {
16    use super::*;
17
18    #[test]
19    fn library_stats_returns_totals_from_an_empty_db() {
20        let conn = Connection::open_in_memory().unwrap();
21        conn.execute_batch(
22            "CREATE TABLE file_hashes (
23                path        TEXT PRIMARY KEY,
24                hash        TEXT NOT NULL,
25                size_bytes  INTEGER,
26                ext         TEXT
27            );",
28        )
29        .unwrap();
30
31        let stats = library_stats(&conn).unwrap();
32        assert_eq!(stats.total_files, 0);
33        assert_eq!(stats.total_size_bytes, 0);
34        assert_eq!(stats.faces_detected, 0); // no faces table - guarded, not an error
35    }
36}