From 3a81f654a9f49649fb6755b6e35649f0102a9572 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 19 Feb 2026 18:17:32 +0100 Subject: all idents as string; move value type; add cow to queries --- database/src/kv/binning.rs | 56 ++++++++++++++++++++++------------------------ database/src/lib.rs | 55 ++++++--------------------------------------- database/src/query_ser.rs | 8 ++++--- 3 files changed, 39 insertions(+), 80 deletions(-) (limited to 'database/src') 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 { 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) { - 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) { + 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)>>>; @@ -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), - Any(Vec), - Match(Path, Value), + All(Vec>), + Any(Vec>), + Match(Path, Value<'a>), Has(Path), } - -#[derive(Debug, Clone)] -pub enum Value { - Tag(Tag), - U32(u32), - U64(u64), - I64(i64), - String(String), - Binary(Vec), -} - -impl From<&str> for Value { - fn from(value: &str) -> Self { - Self::String(value.to_owned()) - } -} -impl From for Value { - fn from(value: String) -> Self { - Self::String(value) - } -} -impl From for Value { - fn from(value: u32) -> Self { - Self::U32(value) - } -} -impl From for Value { - fn from(value: u64) -> Self { - Self::U64(value) - } -} -impl From for Value { - fn from(value: i64) -> Self { - Self::I64(value) - } -} -impl From 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 */ -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(), -- cgit v1.3