Rust 开源内存数据库 VennDB 用位标志查询静态数据
VennDB 是一个用 Rust 编写的仅追加式内存数据库,专为启动时加载、需高频简单过滤的静态数据集设计,通过位标志列实现快速查询。项目源自代理框架 rama 的实际需求,几乎零依赖,基准测试中查询速度超过朴素实现和 SQLite 等传统方案。
报道正文
本文目录2 个章节
VennDB
An append-only in-memory database in Rust for rows queried using bit (flag) columns. This database is designed for a very specific use case where you have mostly static data that you typically load at startup and have to query constantly using very simple filters. Datasets like these can be large and should be both fast and compact.
For the limited usecases where venndb can be applied to,
it has next to no dependencies and is faster then traditional choices,
such as a naive implementation or a more heavy lifted dependency such as Sqlite.
See the benchmarks for more information on this topic.
This project was developed originally in function of rama,
where you can see it being used for example to provide an in-memory (upstream) proxy database.
Do let us know in case you use it as well in your project, such that we can assemble a showcase list.
💬 Come join us at Discord on the #venndb public channel. To ask questions, discuss ideas and ask how venndb may be useful for you.
Index
venndb manual:
technical information:
misc:
Usage
Add venndb as a dependency:
cargo add venndband import the derive macro in the module where you want to use it:
use venndb::{Any, VennDB};
#[derive(Debug, VennDB)]
pub struct Employee {
#[venndb(key)]
id: u32,
name: String,
is_manager: Option<bool>,
is_admin: bool,
#[venndb(skip)]
foo: bool,
#[venndb(filter, any)]
department: Department,
#[venndb(filter)]
country: Option<String>,
}
fn main() {
let db = EmployeeDB::from_iter(employees()).expect("unique ids");
let mut query = db.query();
let employee = query
.is_admin(true)
.is_manager(false)
.department(Department::Engineering)
.execute()
.expect("to have found at least one")
.any();
println!("non-manager admin engineer: {:?}", employee);
}See the full example, the examples (the code in this document is taken from these)
or the "Generated Code Summary" chapter below to learn how to use the VennDB and its generated code.
(注:更多技术实现细节与完整 API 文档请查阅原项目 README)