Struct Datastore

Source
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 clean_maintenance(pool: SqlitePool) -> Result<CleanResult, Error>

Source

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

Wrapper of fail_queued_transactions_raw

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

pub async fn metadata_set_row( &self, key: &str, row_types: Vec<DataType>, ) -> Result<bool, Error>

Set the key as a row Row data is expected to be an Array of Datatype that will then be stored and parsed from strings (json) Length of the array must match the incoming data for this key. Returns true if it wrote to database, false if not

Source

pub async fn metadata_get_row(&self, key: &str) -> Result<Vec<DataType>, Error>

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 get_statistics(&self) -> Result<Statistics, Error>

Return statistics for the database, meant to be used for logging and similar.

§Errors

Will return Err in case of database errors (connections, not existing, etc)

Source

pub async fn insert( &self, key: &str, value: &str, time: f64, 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

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 persist_data(&self) -> Result<(), Error>

Source

pub async fn maybe_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

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

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() -> Self

Create a new datastore with a new temporary file

Panic: will panic if anything fails

Source

pub async fn new_tempfile(dbfile: Arc<NamedTempFile>) -> Self

Create a new datastore from an existing temporary file

Panic: will panic if anything fails

Trait Implementations§

Source§

impl Clone for Datastore

Source§

fn clone(&self) -> Datastore

Returns a duplicate 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 Debug for Datastore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T