Skip to main content

contextdb_core/
traits.rs

1use crate::error::Result;
2use crate::types::*;
3use std::collections::HashMap;
4
5pub trait RelationalExecutor: Send + Sync {
6    fn scan(&self, table: &str, snapshot: SnapshotId) -> Result<Vec<VersionedRow>>;
7    fn scan_filter(
8        &self,
9        table: &str,
10        snapshot: SnapshotId,
11        predicate: &dyn Fn(&VersionedRow) -> bool,
12    ) -> Result<Vec<VersionedRow>>;
13    fn point_lookup(
14        &self,
15        table: &str,
16        col: &str,
17        value: &Value,
18        snapshot: SnapshotId,
19    ) -> Result<Option<VersionedRow>>;
20    fn insert(&self, tx: TxId, table: &str, values: HashMap<ColName, Value>) -> Result<RowId>;
21    fn upsert(
22        &self,
23        tx: TxId,
24        table: &str,
25        conflict_col: &str,
26        values: HashMap<ColName, Value>,
27        snapshot: SnapshotId,
28    ) -> Result<UpsertResult>;
29    fn delete(&self, tx: TxId, table: &str, row_id: RowId) -> Result<()>;
30}
31
32pub trait GraphExecutor: Send + Sync {
33    fn bfs(
34        &self,
35        start: NodeId,
36        edge_types: Option<&[EdgeType]>,
37        direction: Direction,
38        min_depth: u32,
39        max_depth: u32,
40        snapshot: SnapshotId,
41    ) -> Result<TraversalResult>;
42    #[allow(clippy::type_complexity)]
43    fn neighbors(
44        &self,
45        node: NodeId,
46        edge_types: Option<&[EdgeType]>,
47        direction: Direction,
48        snapshot: SnapshotId,
49    ) -> Result<Vec<(NodeId, EdgeType, HashMap<String, Value>)>>;
50    fn insert_edge(
51        &self,
52        tx: TxId,
53        source: NodeId,
54        target: NodeId,
55        edge_type: EdgeType,
56        properties: HashMap<String, Value>,
57    ) -> Result<bool>;
58    fn delete_edge(&self, tx: TxId, source: NodeId, target: NodeId, edge_type: &str) -> Result<()>;
59}
60
61pub trait VectorExecutor: Send + Sync {
62    fn search(
63        &self,
64        index: VectorIndexRef,
65        query: &[f32],
66        k: usize,
67        candidates: Option<&roaring::RoaringTreemap>,
68        snapshot: SnapshotId,
69    ) -> Result<Vec<(RowId, f32)>>;
70    fn insert_vector(
71        &self,
72        tx: TxId,
73        index: VectorIndexRef,
74        row_id: RowId,
75        vector: Vec<f32>,
76    ) -> Result<()>;
77    fn delete_vector(&self, tx: TxId, index: VectorIndexRef, row_id: RowId) -> Result<()>;
78}
79
80pub trait TransactionManager: Send + Sync {
81    fn begin(&self) -> TxId;
82    fn commit(&self, tx: TxId) -> Result<()>;
83    fn rollback(&self, tx: TxId) -> Result<()>;
84    fn snapshot(&self) -> SnapshotId;
85}