pub struct Store { /* private fields */ }Expand description
SQLite-based store for Aranet sensor data.
Implementations§
Source§impl Store
impl Store
Sourcepub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>
Open or create a database at the given path.
Sourcepub fn open_default() -> Result<Self>
pub fn open_default() -> Result<Self>
Open the default database location.
Sourcepub fn open_in_memory() -> Result<Self>
pub fn open_in_memory() -> Result<Self>
Open an in-memory database (for testing).
Sourcepub fn upsert_device(
&self,
device_id: &str,
name: Option<&str>,
) -> Result<StoredDevice>
pub fn upsert_device( &self, device_id: &str, name: Option<&str>, ) -> Result<StoredDevice>
Get or create a device entry.
Sourcepub fn update_device_metadata(
&self,
device_id: &str,
name: Option<&str>,
device_type: Option<DeviceType>,
) -> Result<()>
pub fn update_device_metadata( &self, device_id: &str, name: Option<&str>, device_type: Option<DeviceType>, ) -> Result<()>
Update device metadata (name and type).
This is a simpler version of update_device_info for when you only have
basic device information (e.g., from BLE advertisement or connection).
Sourcepub fn update_device_info(
&self,
device_id: &str,
info: &DeviceInfo,
) -> Result<()>
pub fn update_device_info( &self, device_id: &str, info: &DeviceInfo, ) -> Result<()>
Update device info from DeviceInfo.
Sourcepub fn get_device(&self, device_id: &str) -> Result<Option<StoredDevice>>
pub fn get_device(&self, device_id: &str) -> Result<Option<StoredDevice>>
Get a device by ID.
Sourcepub fn list_devices(&self) -> Result<Vec<StoredDevice>>
pub fn list_devices(&self) -> Result<Vec<StoredDevice>>
List all devices.
Source§impl Store
impl Store
Sourcepub fn insert_reading(
&self,
device_id: &str,
reading: &CurrentReading,
) -> Result<i64>
pub fn insert_reading( &self, device_id: &str, reading: &CurrentReading, ) -> Result<i64>
Insert a current reading.
Sourcepub fn query_readings(&self, query: &ReadingQuery) -> Result<Vec<StoredReading>>
pub fn query_readings(&self, query: &ReadingQuery) -> Result<Vec<StoredReading>>
Query readings with filters.
Sourcepub fn get_latest_reading(
&self,
device_id: &str,
) -> Result<Option<StoredReading>>
pub fn get_latest_reading( &self, device_id: &str, ) -> Result<Option<StoredReading>>
Get the latest reading for a device.
Source§impl Store
impl Store
Sourcepub fn insert_history(
&self,
device_id: &str,
records: &[HistoryRecord],
) -> Result<usize>
pub fn insert_history( &self, device_id: &str, records: &[HistoryRecord], ) -> Result<usize>
Insert history records (with deduplication).
Sourcepub fn query_history(
&self,
query: &HistoryQuery,
) -> Result<Vec<StoredHistoryRecord>>
pub fn query_history( &self, query: &HistoryQuery, ) -> Result<Vec<StoredHistoryRecord>>
Query history records with filters.
Source§impl Store
impl Store
Sourcepub fn get_sync_state(&self, device_id: &str) -> Result<Option<SyncState>>
pub fn get_sync_state(&self, device_id: &str) -> Result<Option<SyncState>>
Get sync state for a device.
Sourcepub fn update_sync_state(
&self,
device_id: &str,
last_index: u16,
total_readings: u16,
) -> Result<()>
pub fn update_sync_state( &self, device_id: &str, last_index: u16, total_readings: u16, ) -> Result<()>
Update sync state after a successful sync.
Sourcepub fn calculate_sync_start(
&self,
device_id: &str,
current_total: u16,
) -> Result<u16>
pub fn calculate_sync_start( &self, device_id: &str, current_total: u16, ) -> Result<u16>
Calculate the start index for incremental sync.
Returns the index to start downloading from (1-based). If the device has new readings since last sync, returns the next index. If this is the first sync, returns 1 to download all.
Source§impl Store
impl Store
Sourcepub fn history_stats(&self, query: &HistoryQuery) -> Result<HistoryStats>
pub fn history_stats(&self, query: &HistoryQuery) -> Result<HistoryStats>
Get aggregate statistics for history records.
Sourcepub fn export_history_csv(&self, query: &HistoryQuery) -> Result<String>
pub fn export_history_csv(&self, query: &HistoryQuery) -> Result<String>
Export history records to CSV format.
Sourcepub fn export_history_json(&self, query: &HistoryQuery) -> Result<String>
pub fn export_history_json(&self, query: &HistoryQuery) -> Result<String>
Export history records to JSON format.
Sourcepub fn import_history_csv(&self, csv_data: &str) -> Result<ImportResult>
pub fn import_history_csv(&self, csv_data: &str) -> Result<ImportResult>
Import history records from CSV format.
Expected CSV format:
timestamp,device_id,co2,temperature,pressure,humidity,radon
2024-01-15T10:30:00Z,Aranet4 17C3C,800,22.5,1013.25,45,Returns the number of records imported (deduplicated by device_id + timestamp).
Sourcepub fn import_history_json(&self, json_data: &str) -> Result<ImportResult>
pub fn import_history_json(&self, json_data: &str) -> Result<ImportResult>
Import history records from JSON format.
Expected JSON format: an array of StoredHistoryRecord objects.
Returns the number of records imported (deduplicated by device_id + timestamp).