pub enum Data {
DbString(String),
DbI32(i32),
DbDateTime(NaiveDateTime),
}Expand description
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§
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Data
impl<'de> Deserialize<'de> for Data
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Data
impl StructuralPartialEq for Data
Auto Trait Implementations§
impl Freeze for Data
impl RefUnwindSafe for Data
impl Send for Data
impl Sync for Data
impl Unpin for Data
impl UnwindSafe for Data
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
Mutably borrows from an owned value. Read more