/* 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 kv; pub mod query_ser; #[cfg(test)] pub mod test_shared; use std::sync::OnceLock; use anyhow::Result; use jellyobject::{ObjectBuffer, Path, Registry}; pub static DEBUG_TAGREG: OnceLock = OnceLock::new(); 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<()>; } pub trait Transaction { fn insert(&mut self, entry: ObjectBuffer) -> Result; fn remove(&mut self, row: RowNum) -> Result<()>; fn update(&mut self, row: RowNum, entry: ObjectBuffer) -> 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(Default)] pub struct Query { pub filter: Filter, pub sort: Sort, } #[derive(Default)] pub enum Sort { #[default] None, Value(ValueSort), TextSearch(Path, String), } 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)] pub enum Filter { #[default] True, All(Vec), Any(Vec), Match(Path, Vec), Has(Path), }