icydb_core/interface/
query.rs1use crate::{
2 Key,
3 db::query::{DeleteQuery, LoadQuery, SaveQuery},
4 runtime_error::{ErrorClass, ErrorOrigin, RuntimeError},
5};
6use thiserror::Error as ThisError;
7
8#[derive(Debug, ThisError)]
13pub enum QueryError {
14 #[error("entity not found: {0}")]
15 EntityNotFound(String),
16}
17
18impl From<QueryError> for RuntimeError {
19 fn from(err: QueryError) -> Self {
20 Self::new(err.class(), ErrorOrigin::Interface, err.to_string())
21 }
22}
23
24impl QueryError {
25 pub(crate) const fn class(&self) -> ErrorClass {
26 match self {
27 Self::EntityNotFound(_) => ErrorClass::Unsupported,
28 }
29 }
30}
31
32pub type LoadHandler = fn(LoadQuery) -> Result<Vec<Key>, RuntimeError>;
34
35pub type SaveHandler = fn(SaveQuery) -> Result<Key, RuntimeError>;
37
38pub type DeleteHandler = fn(DeleteQuery) -> Result<Vec<Key>, RuntimeError>;
40
41#[derive(Clone, Copy)]
47pub struct EntityDispatch {
48 pub entity_id: u64,
49 pub path: &'static str,
50 pub load_keys: LoadHandler,
51 pub save_key: SaveHandler,
52 pub delete_keys: DeleteHandler,
53}