/* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2026 metamuffin */ pub mod helper; pub mod kv; pub mod query_syntax; #[cfg(test)] pub mod test_shared; use anyhow::Result; use jellyobject::{Object, Path, Value}; pub type RowNum = u64; pub type RowIter = Box)>>>; pub trait Database: Send + Sync { fn transaction(&self, f: &mut dyn FnMut(&mut dyn Transaction) -> Result<()>) -> Result<()>; fn debug_info(&self) -> Result { Ok(String::new()) } } #[allow(clippy::type_complexity)] pub trait Transaction { fn insert(&mut self, entry: Box) -> Result; fn remove(&mut self, row: RowNum) -> Result<()>; fn update(&mut self, row: RowNum, entry: Box) -> Result<()>; fn get(&self, row: RowNum) -> Result>>; fn query<'a>( &'a mut self, query: Query, ) -> Result)>> + 'a>>; fn query_single(&mut self, query: Query) -> Result>; fn count(&mut self, query: Query) -> Result; } #[derive(Debug, Default, Clone, PartialEq)] pub struct Query<'a> { pub continuation: Option>, pub filter: Filter<'a>, pub sort: Sort, } #[derive(Debug, Default, Clone, PartialEq)] pub enum Sort { #[default] None, Random(u64), Value(ValueSort), TextSearch(Vec, String), } #[derive(Debug, Clone, PartialEq)] pub struct ValueSort { pub order: SortOrder, pub path: Path, pub multi: MultiBehaviour, pub offset: Option>, } #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] pub enum MultiBehaviour { First, ForEach, Max, Min, Count, } #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] pub enum SortOrder { Ascending, Descending, } #[derive(Debug, Clone, Default, PartialEq)] pub enum Filter<'a> { #[default] True, All(Vec>), Any(Vec>), Match(Path, Value<'a>), Has(Path), }