Crates.io | toiletdb |
lib.rs | toiletdb |
version | 0.1.2 |
source | src |
created_at | 2020-04-11 20:46:29.540762 |
updated_at | 2020-04-12 15:02:09.772005 |
description | Flushes an object to a JSON file. Rust implementation of https://github.com/maxogden/toiletdb |
homepage | |
repository | https://gitlab.com/jakeburden/toiletdb-rs |
max_upload_size | |
id | 228755 |
size | 8,894 |
Flushes an object to a JSON file. Rust implementation of https://github.com/maxogden/toiletdb
A Rust key/value store backed by a JSON file.
use toiletdb::Toiletdb;
// pass the name of the json file to use
fn example() -> Result<(), std::io::Error> {
let mut db = Toiletdb::new("data.json")?;
// write some key/value pairs to data.json
db.write("test", 123)?;
db.write("name", "toiletdb")?;
db.write("rust", true)?;
// get the entire data.json contents
let data: String = db.read()?;
// read a value from a key
if let Some(v) = db.read_key("test") {
assert_eq!(v, 123);
}
// delete a key/value pair
db.delete("test")?;
// reset state and delete data.json
db.flush()?;
Ok(())
}
sets key
to val
inside the JSON file
read the entire JSON file to a String
get the value of a key
deletes key
and it's value from the JSON file
resets state and deletes the JSON file
With cargo-edit:
cargo add toiletdb
Or manually add toiletdb to Cargo.toml
toiletdb = "0.1.0"
MIT