Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

SQLite-based store for Aranet sensor data.

Implementations§

Source§

impl Store

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open or create a database at the given path.

Source

pub fn open_default() -> Result<Self>

Open the default database location.

Source

pub fn open_in_memory() -> Result<Self>

Open an in-memory database (for testing).

Source

pub fn upsert_device( &self, device_id: &str, name: Option<&str>, ) -> Result<StoredDevice>

Get or create a device entry.

Source

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).

Source

pub fn update_device_info( &self, device_id: &str, info: &DeviceInfo, ) -> Result<()>

Update device info from DeviceInfo.

Source

pub fn get_device(&self, device_id: &str) -> Result<Option<StoredDevice>>

Get a device by ID.

Source

pub fn list_devices(&self) -> Result<Vec<StoredDevice>>

List all devices.

Source§

impl Store

Source

pub fn insert_reading( &self, device_id: &str, reading: &CurrentReading, ) -> Result<i64>

Insert a current reading.

Source

pub fn query_readings(&self, query: &ReadingQuery) -> Result<Vec<StoredReading>>

Query readings with filters.

Source

pub fn get_latest_reading( &self, device_id: &str, ) -> Result<Option<StoredReading>>

Get the latest reading for a device.

Source

pub fn count_readings(&self, device_id: Option<&str>) -> Result<u64>

Count readings for a device.

Source§

impl Store

Source

pub fn insert_history( &self, device_id: &str, records: &[HistoryRecord], ) -> Result<usize>

Insert history records (with deduplication).

Source

pub fn query_history( &self, query: &HistoryQuery, ) -> Result<Vec<StoredHistoryRecord>>

Query history records with filters.

Source

pub fn count_history(&self, device_id: Option<&str>) -> Result<u64>

Count history records for a device.

Source§

impl Store

Source

pub fn get_sync_state(&self, device_id: &str) -> Result<Option<SyncState>>

Get sync state for a device.

Source

pub fn update_sync_state( &self, device_id: &str, last_index: u16, total_readings: u16, ) -> Result<()>

Update sync state after a successful sync.

Source

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

Source

pub fn history_stats(&self, query: &HistoryQuery) -> Result<HistoryStats>

Get aggregate statistics for history records.

Source

pub fn export_history_csv(&self, query: &HistoryQuery) -> Result<String>

Export history records to CSV format.

Source

pub fn export_history_json(&self, query: &HistoryQuery) -> Result<String>

Export history records to JSON format.

Source

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).

Source

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).

Auto Trait Implementations§

§

impl !Freeze for Store

§

impl !RefUnwindSafe for Store

§

impl Send for Store

§

impl !Sync for Store

§

impl Unpin for Store

§

impl !UnwindSafe for Store

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more