aboutsummaryrefslogtreecommitdiff
path: root/database/src
diff options
context:
space:
mode:
Diffstat (limited to 'database/src')
-rw-r--r--database/src/kv/binning.rs56
-rw-r--r--database/src/lib.rs55
-rw-r--r--database/src/query_ser.rs8
3 files changed, 39 insertions, 80 deletions
diff --git a/database/src/kv/binning.rs b/database/src/kv/binning.rs
index c41d6e9..253bb5c 100644
--- a/database/src/kv/binning.rs
+++ b/database/src/kv/binning.rs
@@ -51,7 +51,7 @@ impl BinningComponent {
}
}
-impl Filter {
+impl Filter<'_> {
pub fn get_binnings(&self) -> Vec<Binning> {
self.get_bins_inner()
.into_iter()
@@ -88,7 +88,7 @@ impl Filter {
Filter::Match(path, value) => {
vec![vec![(BinningComponent::Match(path.to_owned()), {
let mut co = Vec::new();
- value.write_with_len(&mut co);
+ write_value_with_len(value, &mut co);
co
})]]
}
@@ -99,33 +99,31 @@ impl Filter {
}
}
-impl Value {
- pub fn write_with_len(&self, out: &mut Vec<u8>) {
- match self {
- Value::Tag(tag) => {
- out.extend(4u32.to_be_bytes());
- out.extend(tag.0.to_be_bytes());
- }
- Value::U32(x) => {
- out.extend(4u32.to_be_bytes());
- out.extend(x.to_be_bytes());
- }
- Value::U64(x) => {
- out.extend(8u32.to_be_bytes());
- out.extend(x.to_be_bytes());
- }
- Value::I64(x) => {
- out.extend(8u32.to_be_bytes());
- out.extend(x.to_be_bytes());
- }
- Value::String(s) => {
- out.extend((s.len() as u32).to_be_bytes());
- out.extend(s.as_bytes());
- }
- Value::Binary(s) => {
- out.extend((s.len() as u32).to_be_bytes());
- out.extend(s);
- }
+pub fn write_value_with_len(value: &Value, out: &mut Vec<u8>) {
+ match value {
+ Value::Tag(tag) => {
+ out.extend(4u32.to_be_bytes());
+ out.extend(tag.0.to_be_bytes());
+ }
+ Value::U32(x) => {
+ out.extend(4u32.to_be_bytes());
+ out.extend(x.to_be_bytes());
+ }
+ Value::U64(x) => {
+ out.extend(8u32.to_be_bytes());
+ out.extend(x.to_be_bytes());
+ }
+ Value::I64(x) => {
+ out.extend(8u32.to_be_bytes());
+ out.extend(x.to_be_bytes());
+ }
+ Value::String(s) => {
+ out.extend((s.len() as u32).to_be_bytes());
+ out.extend(s.as_bytes());
+ }
+ Value::Binary(s) => {
+ out.extend((s.len() as u32).to_be_bytes());
+ out.extend(&**s);
}
}
}
diff --git a/database/src/lib.rs b/database/src/lib.rs
index 2ecf3c6..ea12447 100644
--- a/database/src/lib.rs
+++ b/database/src/lib.rs
@@ -9,7 +9,7 @@ pub mod query_ser;
pub mod test_shared;
use anyhow::Result;
-use jellyobject::{ObjectBuffer, Path, Tag};
+use jellyobject::{ObjectBuffer, Path, Value};
pub type RowNum = u64;
pub type RowIter = Box<dyn Iterator<Item = Result<(RowNum, Vec<u8>)>>>;
@@ -33,8 +33,8 @@ pub trait Transaction {
}
#[derive(Default, Clone)]
-pub struct Query {
- pub filter: Filter,
+pub struct Query<'a> {
+ pub filter: Filter<'a>,
pub sort: Sort,
}
@@ -70,52 +70,11 @@ pub enum SortOrder {
}
#[derive(Debug, Clone, Default)]
-pub enum Filter {
+pub enum Filter<'a> {
#[default]
True,
- All(Vec<Filter>),
- Any(Vec<Filter>),
- Match(Path, Value),
+ All(Vec<Filter<'a>>),
+ Any(Vec<Filter<'a>>),
+ Match(Path, Value<'a>),
Has(Path),
}
-
-#[derive(Debug, Clone)]
-pub enum Value {
- Tag(Tag),
- U32(u32),
- U64(u64),
- I64(i64),
- String(String),
- Binary(Vec<u8>),
-}
-
-impl From<&str> for Value {
- fn from(value: &str) -> Self {
- Self::String(value.to_owned())
- }
-}
-impl From<String> for Value {
- fn from(value: String) -> Self {
- Self::String(value)
- }
-}
-impl From<u32> for Value {
- fn from(value: u32) -> Self {
- Self::U32(value)
- }
-}
-impl From<u64> for Value {
- fn from(value: u64) -> Self {
- Self::U64(value)
- }
-}
-impl From<i64> for Value {
- fn from(value: i64) -> Self {
- Self::I64(value)
- }
-}
-impl From<Tag> for Value {
- fn from(value: Tag) -> Self {
- Self::Tag(value)
- }
-}
diff --git a/database/src/query_ser.rs b/database/src/query_ser.rs
index d51ef64..78eee09 100644
--- a/database/src/query_ser.rs
+++ b/database/src/query_ser.rs
@@ -4,9 +4,11 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use crate::{Filter, MultiBehaviour, Query, Sort, SortOrder, Value, ValueSort};
+use jellyobject::Value;
-impl Query {
+use crate::{Filter, MultiBehaviour, Query, Sort, SortOrder, ValueSort};
+
+impl Query<'_> {
pub fn show(&self) -> String {
let mut o = String::new();
if !matches!(self.filter, Filter::True) {
@@ -18,7 +20,7 @@ impl Query {
o
}
}
-impl Filter {
+impl Filter<'_> {
pub fn show(&self) -> String {
match self {
Filter::True => "TRUE".to_string(),