aranet_store/
lib.rs

1//! Local data persistence for Aranet sensor readings.
2//!
3//! This crate provides SQLite-based storage for Aranet sensor data,
4//! enabling offline access, history caching, and efficient queries.
5//!
6//! # Features
7//!
8//! - Store current readings with timestamps
9//! - Cache history records (avoid re-downloading from device)
10//! - Incremental sync tracking per device
11//! - Query by device, time range, with pagination
12//! - Export/import support
13//!
14//! # Example
15//!
16//! ```no_run
17//! use aranet_store::{Store, ReadingQuery};
18//!
19//! let store = Store::open_default()?;
20//!
21//! // Query recent readings
22//! let query = ReadingQuery::new()
23//!     .device("Aranet4 17C3C")
24//!     .limit(10);
25//! let readings = store.query_readings(&query)?;
26//! # Ok::<(), aranet_store::Error>(())
27//! ```
28
29mod error;
30mod models;
31mod queries;
32mod schema;
33mod store;
34
35pub use error::{Error, Result};
36pub use models::{StoredDevice, StoredHistoryRecord, StoredReading, SyncState};
37pub use queries::{HistoryQuery, ReadingQuery};
38pub use store::{HistoryAggregates, HistoryStats, ImportResult, Store};
39
40/// Default database path following platform conventions.
41///
42/// - Linux: `~/.local/share/aranet/data.db`
43/// - macOS: `~/Library/Application Support/aranet/data.db`
44/// - Windows: `C:\Users\<user>\AppData\Local\aranet\data.db`
45pub fn default_db_path() -> std::path::PathBuf {
46    dirs::data_local_dir()
47        .unwrap_or_else(|| std::path::PathBuf::from("."))
48        .join("aranet")
49        .join("data.db")
50}