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.
Example
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);
}
A property can hold a set of values, be queried on what its values look like, and be combined with columns that change while the database is in use:
#[derive(Debug, VennDB)]
#[venndb(name = "Fleet")]
pub struct Server {
#[venndb(key)]
id: u32,
#[venndb(filter)]
tier: Tier,
#[venndb(filter, set)]
endpoints: HashSet<Endpoint>,
#[venndb(filter, any = Location::is_anywhere)]
country: Option<Location>,
gpu: bool,
}
let mut query = fleet.query();
query
.endpoints_where(|endpoint| matches!(endpoint, Endpoint::Http { tls: true, .. }))
.gpu(true);
let draining = RuntimeColumn::new();
draining.set(fleet.index_by_id(&4).unwrap(), true);
let mut query = fleet.query();
query
.country("BE")
.and(Filter::Runtime(&draining, false));
Learn more at https://github.com/plabayo/venndb, where the examples this code is taken from can be found as well.