Crates.io | pickledb |
lib.rs | pickledb |
version | 0.5.1 |
source | src |
created_at | 2019-01-16 07:10:58.911913 |
updated_at | 2022-04-26 07:23:22.591252 |
description | A lightweight and simple key-value store written in Rust, heavily inspired by Python's PickleDB (https://pythonhosted.org/pickleDB/) |
homepage | https://github.com/seladb/pickledb-rs |
repository | https://github.com/seladb/pickledb-rs |
max_upload_size | |
id | 108860 |
size | 145,200 |
PickleDB is a lightweight and simple key-value store written in Rust, heavily inspired by Python's PickleDB
use pickledb::{PickleDb, PickleDbDumpPolicy, SerializationMethod};
fn main() {
// create a new DB with AutoDump (meaning every change is written to the file)
// and with Json serialization (meaning DB will be dumped to file as a Json object)
let mut db = PickleDb::new("example.db", PickleDbDumpPolicy::AutoDump, SerializationMethod::Json);
// set the value 100 to the key 'key1'
db.set("key1", &100).unwrap();
// print the value of key1
println!("The value of key1 is: {}", db.get::<i32>("key1").unwrap());
// load the DB from the same file
let db2 = PickleDb::load("example.db", PickleDbDumpPolicy::DumpUponRequest, SerializationMethod::Json).unwrap();
// print the value of key1
println!("The value of key1 as loaded from file is: {}", db2.get::<i32>("key1").unwrap());
}
This crate works with Cargo and can be found in crates.io
Add this to your Cargo.toml
:
[dependencies]
pickledb = "0.5.1"
All documentation for this crate can be found in docs.rs
There are currently two examples shipped with PickleDB:
DumpUponRequest
policy no longer dumps on Drop
ignore
to no_run
so generated docs don't contain untested warningslextend
to take iterators of references rather than a slice of valuesload_test()
Cargo.toml
to allow them to be run via CargoPath
and PathBuf
instead of strings to describe DB pathslcreate()
, ladd()
and lextend()
can be chained