pub struct Datastore { /* private fields */ }
Implementations§
Source§impl Datastore
impl Datastore
pub async fn has_transaction(&self, token: &str) -> Result<bool, Error>
pub async fn transaction_add( &self, key: &str, expected: &str, target: &str, token: &str, ) -> Result<(), Error>
pub async fn transaction_get( &self, prefix: &str, ) -> Result<Vec<Transaction>, Error>
pub async fn transaction_fail( &self, transaction_id: i64, timefail: bool, ) -> Result<u64, Error>
pub async fn transaction_pass( &self, transaction_id: i64, timefail: bool, ) -> Result<u64, Error>
Sourcepub async fn transaction_fail_pending(&self) -> Result<u64, Error>
pub async fn transaction_fail_pending(&self) -> Result<u64, Error>
Fail all pending transactions
Source§impl Datastore
impl Datastore
pub async fn clean_maintenance(pool: SqlitePool) -> Result<CleanResult, Error>
Sourcepub async fn fail_queued_transactions(&self) -> Result<i32, Error>
pub async fn fail_queued_transactions(&self) -> Result<i32, Error>
Wrapper of fail_queued_transactions_raw
Source§impl Datastore
impl Datastore
pub async fn metadata_get_names(&self) -> Result<Vec<Metadata>, Error>
pub async fn metadata_get_units(&self) -> Result<Vec<Metadata>, Error>
pub async fn metadata_get_descriptions(&self) -> Result<Vec<Metadata>, Error>
pub async fn metadata_get_enum(&self) -> Result<Vec<Metadata>, Error>
pub async fn get_metadata(&self, key: &str) -> Result<Option<Metadata>, Error>
pub async fn get_all_metadata(&self) -> Result<Vec<Metadata>, Error>
pub async fn get_all_internal_metadata(&self) -> Result<Vec<Metadata>, Error>
Sourcepub async fn metadata_set_name(
&self,
key: &str,
name: &str,
) -> Result<bool, Error>
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.
Sourcepub async fn metadata_set_unit(
&self,
key: &str,
unit: &str,
) -> Result<bool, Error>
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
Sourcepub async fn metadata_set_description(
&self,
key: &str,
description: &str,
) -> Result<bool, Error>
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.
Sourcepub async fn metadata_set_mode(
&self,
key: &str,
mode: &SensorMode,
) -> Result<bool, Error>
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.
Sourcepub async fn metadata_set_enum(
&self,
key: &str,
value_map: &ValueMap,
) -> Result<bool, Error>
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.
Sourcepub async fn metadata_set_row(
&self,
key: &str,
row_types: Vec<DataType>,
) -> Result<bool, Error>
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
pub async fn metadata_get_row(&self, key: &str) -> Result<Vec<DataType>, Error>
Source§impl Datastore
impl Datastore
Sourcepub async fn new(pool: SqlitePool) -> Result<Self, Error>
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.
pub fn pool(&self) -> SqlitePool
Sourcepub async fn get_statistics(&self) -> Result<Statistics, Error>
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)
Sourcepub async fn insert(
&self,
key: &str,
value: &str,
time: f64,
timefail: bool,
) -> Result<(), Error>
pub async fn insert( &self, key: &str, value: &str, time: f64, timefail: bool, ) -> Result<(), Error>
Sourcepub async fn insert_bulk(
&self,
data: Vec<Metric>,
timefail: bool,
) -> Result<(), Error>
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.
Sourcepub async fn should_persist(&self) -> Result<bool, Error>
pub async fn should_persist(&self) -> Result<bool, Error>
Sourcepub async fn should_persist_age(&self) -> Result<bool, Error>
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.
pub async fn persist_data(&self) -> Result<(), Error>
pub async fn maybe_persist_data(&self) -> Result<(), Error>
Source§impl Datastore
impl Datastore
pub async fn get_batch(&self, size: u32) -> Result<Vec<TXMetric>, Error>
pub async fn get_internal_batch( &self, size: u32, ) -> Result<Vec<TXMetric>, Error>
pub async fn drop_batch(&self, ids: &[i64]) -> Result<(), Error>
pub async fn fix_timefail(&self, adjust: f32) -> Result<u64, Error>
pub async fn get_last_datapoint(&self, key: &str) -> Result<Metric, Error>
pub async fn get_latest_logdata(&self) -> Result<Vec<Metric>, Error>
Source§impl Datastore
impl Datastore
Sourcepub async fn temporary() -> Self
pub async fn temporary() -> Self
Create a new datastore with a new temporary file
Panic: will panic if anything fails
Sourcepub async fn new_tempfile(dbfile: Arc<NamedTempFile>) -> Self
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§
Auto Trait Implementations§
impl Freeze for Datastore
impl !RefUnwindSafe for Datastore
impl Send for Datastore
impl Sync for Datastore
impl Unpin for Datastore
impl !UnwindSafe for Datastore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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