in memory Rust database to query your data like a Venn diagram
APACHE-2.0 License
Bot releases are hidden (Show)
New Features:
#15
]: support multi dimensional filter options to be filtered in groupExample:
use venndb::{Any, VennDB};
#[derive(Debug, VennDB)]
pub struct Value {
#[venndb(filter)]
pub foo: String,
pub bar: u32,
}
let db = ValueDB::from_iter([
Value {
foo: "a".to_owned(),
bar: 8,
},
Value {
foo: "b".to_owned(),
bar: 12,
},
Value {
foo: "c".to_owned(),
bar: 16,
},
].into_Iter()).unwrap();
let mut query = db.query();
query.foo(MyString("a".to_owned()));
query.foo(MyString("c".to_owned()));
let values: Vec<_> = query.execute().unwrap().iter().collect();
assert_eq!(values.len(), 2);
assert_eq!(values[0].bar, 8);
assert_eq!(values[0].bar, 16);
Published by GlenDC 6 months ago
Breaking Changes:
#7
]: correct the behaviour of any filter map query values:
New Features:
#8
]: support custom validations of rows prior to appending themExample:
#[derive(Debug, VennDB)]
#[venndb(name = "MyDB", validator = my_validator_fn)]
pub struct Value {
pub foo: String,
pub bar: u32,
}
fn my_validator_fn(value: &Value) -> bool {
!value.foo.is_empty() && value.bar > 0
}
let mut db = MyDB::default();
assert!(db.append(Value {
foo: "".to_owned(),
bar: 42,
}).is_err()); // fails because foo == empty
Published by GlenDC 6 months ago
Breaking changes:
#6
] query filter maps now accept arguments as impl Into<T>
instead of T
,value.into()
,.into()
(like) calls that you previously had to add yourself;Bug Fixes from 0.2.1:
#5
] any filters now also allow rows to match on unknown filter map variants.
MyType
filter map and have not a single row that has "foo"
as value,assert!(Any::is_any(value: MyType))
will still work.any
rows would only hitPublished by GlenDC 6 months ago
A backwards compatible patch for v0.2.0
to support rows that allow any value for a specific column.
Non-Breaking changes:
#[venndb(any)]
filters;
T
filter maps, where T: ::venndb::Any
;bool
filters cannot be any
as bool
doesn't implement the ::venndb::Any
trait;any
will match regardless of the query filter used for that property;Example usage:
use venndb::{Any, VennDB};
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum Department {
Any,
Hr,
Engineering,
}
impl Any for Department {
fn is_any(&self) -> bool {
self == Department::Any
}
}
#[derive(Debug, VennDB)]
pub struct Employee {
name: String,
#[venndb(filter, any)]
department: Department,
}
let db = EmployeeDB::from_iter([
Employee { name: "Jack".to_owned(), department: Department::Any },
Employee { name: "Derby".to_owned(), department: Department::Hr },
]);
let mut query = db.query();
// will match Jack and Derby, as Jack is marked as Any, meaning it can work for w/e value
let hr_employees: Vec<_> = query.department(Department::Hr).execute().unwrap().iter().collect();
assert_eq!(hr_employees.len(), 2);
In case you combine it with the filter map property being optional (department: Option<Department>
),
then it will still work the same, where rows with None
are seen as nothing at all and just ignored.
This has no affect on the correct functioning of Any
.
Published by GlenDC 6 months ago
Breaking Changes:
None
;None
will result in same hash... so it is unlikelyOption<T>
already used by someone;0.1*
might have already used Option
in a different way;While this changes behaviour of filters
and filter maps
it is unlikely that someone was already using
Option<T>
for these types before, as their ergonomics have been a bit weird prior to this version.
Even more so for filter maps
it could have resulted in panics.
Updated Example from 0.1:
use venndb::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)]
department: Department,
#[venndb(filter)]
country: Option<String>,
}
fn main() {
let db = EmployeeDB::from_iter(/* .. */);
let mut query = db.query();
let employee = query
.is_admin(true)
.is_manager(false) // rows which have `None` for this property will NOT match this filter
.department(Department::Engineering)
.execute()
.expect("to have found at least one")
.any();
println!("non-manager admin engineer: {:?}", employee);
// as we didn't specify a `country` filter, even rows without a country specified will
// match here if they match the defined (query) filters)
}
Non-Breaking Changes:
Published by GlenDC 6 months ago
Non-Breaking Changes:
missing_docs
): missing documentation for a variant
;Published by GlenDC 6 months ago
Implement the first version of this library, venndb
.
Released as venndb
(0.1.0) and venndb-macros
(0.1.0).
API Example:
use venndb::VennDB
#[derive(Debug, VennDB)]
pub struct Employee {
#[venndb(key)]
id: u32,
name: String,
is_manager: bool,
is_admin: bool,
#[venndb(skip)]
foo: bool,
#[venndb(filter)]
department: Department,
}
fn main() {
let db = EmployeeDB::from_iter(/* .. */);
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);
}
This API, using nothing more then a derive
macro allows to:
database
;filter
fields;key
;The crate comes with examples and a detailed README.
Please share with us if you have any feedback about this first version,
how you are using it, what you would like different, etc.