[][src]Enum vdb::Data

pub enum Data {
    DbString(String),
    DbI32(i32),
    DbDateTime(NaiveDateTime),
}

A basic database system to store key/value pairs with few dependencies.

Examples

use vdb::{Db, Entry, Predicate};
let mut db = Db::new("test-db");
let row_1 = db.add_row(vec![
        Entry::new_string("word", "cocina"),
        Entry::new_string("translation", "cuisine"),
        Entry::new_string("translation", "kitchen"),
]);
let row_2 = db.add_row(vec![
        Entry::new_string("word", "coche"),
        Entry::new_string("translation", "car"),
]);

// Load and save
db.save();
let mut new_db = Db::load("test-db").unwrap();
let row_ids = new_db.find_all_row_ids();
assert_eq!(row_ids.len(), 2);

// Find rows
let row_ids = db.find_row_ids_by_predicate(&vec![Predicate::new_equal_string("word", "coche")], None);
assert_eq!(row_ids, [row_2]);
let entries = db.entries_from_row_ids(&row_ids, &["translation"]);
assert_eq!(entries[0][0], Entry::new_string("translation", "car"));

// Delete
let coche = db.find_first_row_id_by_value("word", &Db::db_string("coche"));
assert_eq!(coche, Some(row_2));
db.delete_rows(&[row_1, row_2]);
let no_coche = db.find_first_row_id_by_value("word", &Db::db_string("coche"));
assert_eq!(no_coche, None);

Data types currently implemented in the database

Variants

DbString(String)DbI32(i32)DbDateTime(NaiveDateTime)

Methods

impl Data[src]

pub fn now() -> Data[src]

Returns new DbDateTime with current time as timestamp

pub fn date(&self) -> Option<String>[src]

Trait Implementations

impl Clone for Data[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl PartialEq<Data> for Data[src]

impl Eq for Data[src]

impl Display for Data[src]

impl Debug for Data[src]

impl Hash for Data[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Serialize for Data[src]

impl<'de> Deserialize<'de> for Data[src]

Auto Trait Implementations

impl Sync for Data

impl Send for Data

impl Unpin for Data

impl RefUnwindSafe for Data

impl UnwindSafe for Data

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]