Crate emseries

Source
Expand description

An Embedded Time Series Database

This library provides a low-intensity time series database meant to be embedded inside of an application.

From the signature of the series

pub struct Series<T: Clone + Recordable + DeserializeOwned + Serialize> {

you can know that you must parameterize the series over the data type that you want to store, which must also have several traits implemented.

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
struct BikeTrip {
    datetime: DateTime<Utc>,
    distance: Distance,
    duration: Duration,
    comments: String,
}

impl Recordable for BikeTrip {
    fn timestamp(&self) -> DateTime<Utc> {
        self.datetime
    }
    fn tags(&self) -> Vec<String> {
        Vec::new()
    }
}

Recordable requires implementations for timestamp and tags, both of which can be used for searching for records, and both of which may be used for indexing in the future.

The series can only store a single data type, but you can always store multiple data types by wrapping them into a single enum.

Open the series:

let mut ts: Series<BikeTrip> = Series::open("var/bike_trips.json")
    .expect("expect the time series to open correctly");

The series file will be created if it does not already exist. If it does already exist, the existing data will be read into memory and made available.

Note: all of the data is read into memory at once. For human-scale things, this probably takes up very little memory, but this software is not optimized for IoT scale deployments. Additionally, this library assumes only one process is writing to the file. Behavior from more than one process writing to the file is currently undefined.

Structs§

  • Specify two criteria that must both be matched.
  • This is a wrapper around date time objects, using timezones from the chroon-tz database and providing string representation and parsing of the form “ ”, i.e., “2019-05-15T14:30:00Z US/Central”. The to_string method, and serde serialization will produce a string of this format. The parser will accept an RFC3339-only string of the forms “2019-05-15T14:30:00Z”, “2019-05-15T14:30:00+00:00”, and also an “RFC3339 Timezone Name” string.
  • Specify the ending time for a search. This consists of a UTC timestamp and a specifier as to whether the exact time is included in the search criteria.
  • Specify two criteria, either of which may be matched.
  • An open time series database.
  • Specify the starting time for a search. This consists of a UTC timestamp and a specifier as to whether the exact time is included in the search criteria.
  • Specify a list of tags that must exist on the record.
  • Uniquely identifies a record.

Enums§

  • Errors for the database

Traits§

  • This trait is used for constructing queries for searching the database.
  • Any element to be put into the database needs to be Recordable. This is the common API that will aid in searching and later in indexing records.

Functions§

  • Specify a criteria that searches for records matching an exact time.
  • Specify a criteria that searches for all records within a time range.