diff options
| -rw-r--r-- | common/object/src/lib.rs | 3 | ||||
| -rw-r--r-- | common/object/src/value.rs | 29 | ||||
| -rw-r--r-- | common/src/lib.rs | 2 | ||||
| -rw-r--r-- | database/src/lib.rs | 44 |
4 files changed, 42 insertions, 36 deletions
diff --git a/common/object/src/lib.rs b/common/object/src/lib.rs index 7c97bee..ea64fd4 100644 --- a/common/object/src/lib.rs +++ b/common/object/src/lib.rs @@ -12,14 +12,13 @@ mod registry; mod tests; mod value; pub use buffer::*; -use bytemuck::NoUninit; pub use registry::*; pub use value::*; use std::marker::PhantomData; #[repr(transparent)] -#[derive(NoUninit, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct Tag(pub u32); #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] diff --git a/common/object/src/value.rs b/common/object/src/value.rs index 1b24e79..aad6101 100644 --- a/common/object/src/value.rs +++ b/common/object/src/value.rs @@ -43,7 +43,7 @@ impl ValueStore for &str { impl Value<'_> for u32 { const ALIGNED: bool = true; fn load_aligned(buf: &[u32]) -> Option<Self> { - buf.get(0).copied() + buf.get(0).copied().map(u32::from_be) } } impl ValueStore for u32 { @@ -51,7 +51,7 @@ impl ValueStore for u32 { true } fn store_aligned(&self, buf: &mut Vec<u32>) { - buf.push(*self); + buf.push(self.to_be()); } fn size(&self) -> usize { 4 @@ -60,8 +60,8 @@ impl ValueStore for u32 { impl Value<'_> for u64 { const ALIGNED: bool = false; fn load_aligned(buf: &[u32]) -> Option<Self> { - let hi = *buf.get(0)? as u64; - let lo = *buf.get(1)? as u64; + let hi = u32::from_be(*buf.get(0)?) as u64; + let lo = u32::from_be(*buf.get(1)?) as u64; Some(hi << 32 | lo) } } @@ -70,8 +70,8 @@ impl ValueStore for u64 { true } fn store_aligned(&self, buf: &mut Vec<u32>) { - buf.push((self >> 32) as u32); - buf.push(*self as u32); + buf.push(((self >> 32) as u32).to_be()); + buf.push((*self as u32).to_be()); } fn size(&self) -> usize { 8 @@ -124,20 +124,3 @@ impl ValueStore for &[u8] { self.len() } } -impl<'a> Value<'a> for &'a [u32] { - const ALIGNED: bool = true; - fn load_aligned(buf: &'a [u32]) -> Option<Self> { - Some(buf) - } -} -impl ValueStore for &[u32] { - fn is_aligned(&self) -> bool { - true - } - fn store_aligned(&self, buf: &mut Vec<u32>) { - buf.extend(*self); - } - fn size(&self) -> usize { - self.len() * 4 - } -} diff --git a/common/src/lib.rs b/common/src/lib.rs index 2cbbfce..5641386 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -59,7 +59,7 @@ fields! { CH_START: f64 = 29 "start"; CH_END: f64 = 30 "end"; - CH_NAME: f64 = 31 "name"; + CH_NAME: &str = 31 "name"; LANG_NATIVE: &str = 0xa001 "native"; LANG_ENG: &str = 0xa002 "eng"; diff --git a/database/src/lib.rs b/database/src/lib.rs index 32d160b..df314b6 100644 --- a/database/src/lib.rs +++ b/database/src/lib.rs @@ -10,16 +10,40 @@ pub mod table; pub type Pad32 = u32; -use jellycommon::jellyobject::{Object, Tag, TypedTag}; +use jellycommon::jellyobject::Tag; -enum Query<'a> { - MatchStr(Match<'a, &'a str>), - MatchF64(Match<'a, f64>), - MatchU64(Match<'a, u64>), - MatchTag(Match<'a, Tag>), - Has(Path<'a>), +pub struct Query { + pub filter: Filter, + pub sort: Sort, } -pub struct Match<'a, T>(pub TypedPath<'a, T>, pub T); -pub struct TypedPath<'a, T>(pub &'a [TypedTag<Object<'static>>], pub TypedTag<T>); -pub struct Path<'a>(pub &'a [TypedTag<Object<'static>>], pub Tag); +pub enum Sort { + None, + Value(Vec<ValueSortComponent>), + TextSearch(Path, String), +} +pub struct ValueSortComponent { + pub order: SortOrder, + pub path: Path, + pub multi: MultiBehaviour, + pub offset: Option<Vec<u8>>, +} +pub enum MultiBehaviour { + First, + ForEach, + Max, + Min, + Count, +} +pub enum SortOrder { + Ascending, + Descending, +} +pub enum Filter { + And(Vec<Filter>), + Or(Vec<Filter>), + Match(Path, Vec<u8>), + Has(Path), +} + +pub struct Path(pub Vec<Tag>); |