icydb_core/interface/
query.rs

1use crate::{
2    Error, Key,
3    db::query::{DeleteQuery, LoadQuery, SaveQuery},
4    interface::InterfaceError,
5};
6use thiserror::Error as ThisError;
7
8///
9/// QueryError
10///
11
12#[derive(Debug, ThisError)]
13pub enum QueryError {
14    #[error("entity not found: {0}")]
15    EntityNotFound(String),
16}
17
18impl From<QueryError> for Error {
19    fn from(err: QueryError) -> Self {
20        InterfaceError::from(err).into()
21    }
22}
23
24/// Function pointer that executes a load query for a specific entity type.
25pub type LoadHandler = fn(LoadQuery) -> Result<Vec<Key>, Error>;
26
27/// Function pointer that executes a save query for a specific entity type.
28pub type SaveHandler = fn(SaveQuery) -> Result<Key, Error>;
29
30/// Function pointer that executes a delete query for a specific entity type.
31pub type DeleteHandler = fn(DeleteQuery) -> Result<Vec<Key>, Error>;
32
33/// Metadata and typed handlers for a single entity path.
34///
35/// Generated actor code exposes a `dispatch_entity(path)` function that returns this,
36/// letting you authorize per-entity before invoking the handlers. No canister
37/// endpoints are generated automatically.
38#[derive(Clone, Copy)]
39pub struct EntityDispatch {
40    pub entity_id: u64,
41    pub path: &'static str,
42    pub load_keys: LoadHandler,
43    pub save_key: SaveHandler,
44    pub delete_keys: DeleteHandler,
45}