pub struct Datastore { /* private fields */ }

Implementations§

source§

impl Datastore

source

pub async fn has_transaction(&self, token: &str) -> Result<bool, Error>

source

pub async fn transaction_add( &self, key: &str, expected: &str, target: &str, token: &str ) -> Result<(), Error>

source

pub async fn transaction_get( &self, prefix: &str ) -> Result<Vec<Transaction>, Error>

source

pub async fn transaction_fail( &self, transaction_id: i64, timefail: bool ) -> Result<u64, Error>

source

pub async fn transaction_pass( &self, transaction_id: i64, timefail: bool ) -> Result<u64, Error>

source

pub async fn transaction_fail_pending(&self) -> Result<u64, Error>

Fail all pending transactions

source§

impl Datastore

source

pub async fn delete_old_transactions(&self) -> Result<u64, Error>

source

pub async fn fail_queued_transactions(&self) -> Result<u64, Error>

source

pub async fn delete_old_logdata(&self) -> Result<u64, Error>

source

pub async fn delete_random_data(&self) -> Result<u64, Error>

Delete random data

source

pub async fn need_vacuum_or_shrink(&self) -> Result<usize, Error>

source§

impl Datastore

source

pub async fn metadata_get_names(&self) -> Result<Vec<Metadata>, Error>

source

pub async fn metadata_get_units(&self) -> Result<Vec<Metadata>, Error>

source

pub async fn metadata_get_descriptions(&self) -> Result<Vec<Metadata>, Error>

source

pub async fn metadata_get_enum(&self) -> Result<Vec<Metadata>, Error>

source

pub async fn get_metadata(&self, key: &str) -> Result<Option<Metadata>, Error>

source

pub async fn get_all_metadata(&self) -> Result<Vec<Metadata>, Error>

source

pub async fn metadata_set_name( &self, key: &str, name: &str ) -> Result<bool, Error>

Set the name for a sensor If the name was already set, replaces it.

source

pub async fn metadata_set_unit( &self, key: &str, unit: &str ) -> Result<bool, Error>

Set the unit for an key. If the unit is already set, will return some kind of Error. Returns true if it wrote to database, false if not

source

pub async fn metadata_set_description( &self, key: &str, description: &str ) -> Result<bool, Error>

Set the description for a sensor If the description was already set, replaces it.

source

pub async fn metadata_set_mode( &self, key: &str, mode: &SensorMode ) -> Result<bool, Error>

Set the mode for a sensor. (ReadOnly, ReadWrite, WriteOnly) If the mode was already set, replaces it.

source

pub async fn metadata_set_enum( &self, key: &str, value_map: &ValueMap ) -> Result<bool, Error>

Set the enum (lookup table) for a sensor If the enum was already set, replaces it.

source§

impl Datastore

source

pub async fn new(pool: SqlitePool) -> Result<Self, Error>

Construct a datastore Takes an pre-configured and migrated DB pool and opens a temp buffer.

Errors

Any SQLx Error is returned.

source

pub fn pool(&self) -> SqlitePool

source

pub async fn count_transactions(&self) -> Result<i64, Error>

Helper, count the remaining transaction in the table.

source

pub async fn count_metrics(&self) -> Result<i32, Error>

Helper, count the amount of “customer” values in the database

source

pub async fn count_metrics_internal(&self) -> Result<i32, Error>

Helper, count the amount of “modio” values in the database

source

pub async fn count_metrics_removed(&self) -> Result<i32, Error>

Helper, count the amount of “deleted” values in the database

source

pub async fn count_metrics_timefail(&self) -> Result<i32, Error>

Helper, count the amount of “timefail” values in the database

source

pub async fn insert( &self, key: &str, value: &str, time: i64, timefail: bool ) -> Result<(), Error>

Insert a single data-point into the database or buffer

Errors

Any SQL error.

source

pub async fn insert_bulk( &self, data: Vec<Metric>, timefail: bool ) -> Result<(), Error>

Insert a batch of data-points into the datastore Stores all the keys to permanent storage, but may buffer actual log values.

Errors

Any SQL error.

source§

impl Datastore

source

pub async fn should_persist(&self) -> Result<bool, Error>

Check if we should persist data to disk according to heurestic

Errors

Any SQL errors are returned.

source

pub async fn should_persist_age(&self) -> Result<bool, Error>

Check if we should persist data to disk according to age heurestic

Errors

Any SQL errors are returned.

source

pub async fn should_persist_key(&self, key: &str) -> Result<bool, Error>

Check if we need to persist data to have current data for this key

Errors

Key missing or other SQL error.

source

pub async fn persist_data(&self) -> Result<(), Error>

source§

impl Datastore

source

pub async fn get_batch(&self, size: u32) -> Result<Vec<TXMetric>, Error>

source

pub async fn get_internal_batch( &self, size: u32 ) -> Result<Vec<TXMetric>, Error>

source

pub async fn drop_batch(&self, ids: &[i64]) -> Result<(), Error>

source§

impl Datastore

source

pub async fn fix_timefail(&self, adjust: f32) -> Result<u64, Error>

source§

impl Datastore

source

pub async fn get_last_datapoint(&self, key: &str) -> Result<Metric, Error>

source

pub async fn get_latest_logdata(&self) -> Result<Vec<Metric>, Error>

source§

impl Datastore

source

pub async fn temporary() -> Datastore

Trait Implementations§

source§

impl Clone for Datastore

source§

fn clone(&self) -> Datastore

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for Datastore

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

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

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

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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