1个不稳定版本
新 0.1.0 | 2024年8月14日 |
---|
#88 在 数据库实现
106 每月下载量
27KB
602 行
docDB
docDB是一个轻量级简单的键值存储。它受到Python的PickleDB的启发
如何使用
use docdb::{DocDb, DumpPolicy, 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 = docdb::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 = docdb::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());
}
安装
在cargo.toml中添加依赖
[dependencies]
docdb = "0.1.0"
依赖
~0.4–1.4MB
~32K SLoC