7 个版本 (4 个重大更新)
0.5.1 | 2022年4月26日 |
---|---|
0.5.0 | 2022年4月20日 |
0.4.1 | 2020年3月29日 |
0.4.0 | 2019年5月15日 |
0.1.0 | 2019年1月16日 |
#29 in 数据库实现
每月下载量 35,673
在 20 个crate中(19 个直接) 使用
79KB
887 代码行数,不包括注释
PickleDB
PickleDB是用Rust编写的轻量级简单键值存储,深受Python的PickleDB的启发
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());
}
安装
此crate与Cargo一起使用,可在crates.io中找到。将其添加到您的Cargo.toml
[dependencies]
pickledb = "0.5.1"
文档
有关此crate的所有文档均可在此处找到:docs.rs
示例
目前PickleDB附带两个示例
- Hello World 展示了PickleDB的基本用法:创建新的DB,从文件加载DB,获取/设置不同类型的关键字/值对,等等
- 列表 展示了如何在PickleDB中使用列表:创建新的列表,从列表中添加/删除项目,从列表中检索项目,删除列表,等等
变更日志
版本 0.5.1
- 修复:添加缺少的JSON功能门
版本 0.5.0
- 使用功能打开/关闭文件格式
DumpUponRequest
策略不再在Drop
上导出- (内部) 将CI从TravisCI切换到GitHub Actions
版本 0.4.1
- 提高依赖项版本,以修复其中一些发现的安全漏洞
版本 0.4.0
- 将所有doc测试从
ignore
更改为no_run
,以便生成的文档不包含未经测试的警告 - 将两个
lextend
实例更改为接受引用的迭代器,而不是值的切片 - 修复了
load_test()
中的错误 - 修复了 rustfmt 和 clippy 警告
- 在
Cargo.toml
中添加了示例,以便可以通过Cargo运行它们
版本 0.3.0
- 添加了新的序列化选项。现在PickleDB支持 JSON、Bincode、YAML 和 CBOR 序列化
- 添加了适当的错误处理(《问题 #3》)
- 使用
Path
和PathBuf
代替字符串来描述数据库路径 - 代码组织更加合理
版本 0.2.0
- 使用临时文件以崩溃安全的方式将数据库导出到文件(感谢 Reddit 上的 jamwt 提供的建议:https://www.reddit.com/r/rust/comments/agumun/check_out_pickledb_a_lightweight_and_simple/ee987j0)
- 扩展列表变得更容易,并且可以对
lcreate()
、ladd()
和lextend()
进行链式调用 - 添加了数据库中键和值的迭代器
- 添加了列表中项的迭代器
依赖项
~0.4–1.5MB
~33K SLoC