Extending the Basic KV Store
Key/Value stores are super fast and effective. and Sled is one of the best out there.
This crate seeks to better organize the basic K/V data so that it has much more meaning. Something closer to the kind of organization you would get in a document store but running on top of Sled for maximum speed.
The following example attempts to organize Japanese Machines into a dataset of vehicles & electronics.
pub mod db;
use blazeup::kv;
use std::{error::Error, path::Path, result::Result };
fn main() -> Result<(), Box<dyn Error>> {
let path = Path::new("./db");
kv::reset(Some(&path))?;
kv::init(Some(&path))?;
let bucket = "Japanese-Machines";
let vehicles = kv::Record{
name:"models".into(), values: vec![
kv::Types::String("Toyota".into()),
kv::Types::String("Subaru".into()),
]
};
kv::set(&bucket, "vehicles", vehicles.clone())?;
let tvs = kv::Record{
name:"models".into(), values: vec![
kv::Types::String("Sony".into()),
kv::Types::String("Sharp".into()),
]
};
kv::set(&bucket, "electronics-tvs", tvs.clone())?;
let radios = kv::Record{
name:"old-models".into(), values: vec![
kv::Types::String("Hitachi".into()),
kv::Types::String("Toshiba".into()),
]
};
kv::set(&bucket, "electronics-radios", radios.clone())?;
let ts: HashMap<_, _> = kv::tx! {
"tx-vehicles" => vehicles ,
"tx-radios" => radios ,
"tx-tvs" => tvs
};
kv::transaction(bucket, ts)?;
let value = kv::get(&bucket, "electronics-radios");
println!("{:#?}", value);
let filter = kv::Filter{
key : Some("electronics*"),
name:Some("old*")
};
let all = kv::get_all(&bucket, Some(filter));
println!("{:#?}", all);
}