gluesql_core/store/
index.rs1use {
2 super::RowIter,
3 crate::{
4 ast::{IndexOperator, OrderByExpr},
5 data::Value,
6 result::{Error, Result},
7 },
8 serde::Serialize,
9 std::fmt::Debug,
10 thiserror::Error as ThisError,
11};
12
13#[derive(ThisError, Serialize, Debug, PartialEq, Eq)]
14pub enum IndexError {
15 #[error("table not found: {0}")]
16 TableNotFound(String),
17
18 #[error("index name already exists: {0}")]
19 IndexNameAlreadyExists(String),
20
21 #[error("index name does not exist: {0}")]
22 IndexNameDoesNotExist(String),
23
24 #[error("conflict - table not found: {0}")]
25 ConflictTableNotFound(String),
26
27 #[error("conflict - update failed - index value")]
28 ConflictOnEmptyIndexValueUpdate,
29
30 #[error("conflict - delete failed - index value")]
31 ConflictOnEmptyIndexValueDelete,
32
33 #[error("conflict - scan failed - index value")]
34 ConflictOnEmptyIndexValueScan,
35
36 #[error("conflict - index sync - delete index data")]
37 ConflictOnIndexDataDeleteSync,
38}
39
40pub trait Index {
41 fn scan_indexed_data<'a>(
42 &'a self,
43 _table_name: &str,
44 _index_name: &str,
45 _asc: Option<bool>,
46 _cmp_value: Option<(&IndexOperator, Value)>,
47 ) -> Result<RowIter<'a>> {
48 Err(Error::StorageMsg(
49 "[Storage] Index::scan_indexed_data is not supported".to_owned(),
50 ))
51 }
52}
53
54pub trait IndexMut {
55 fn create_index(
56 &mut self,
57 _table_name: &str,
58 _index_name: &str,
59 _column: &OrderByExpr,
60 ) -> Result<()> {
61 let msg = "[Storage] Index::create_index is not supported".to_owned();
62
63 Err(Error::StorageMsg(msg))
64 }
65
66 fn drop_index(&mut self, _table_name: &str, _index_name: &str) -> Result<()> {
67 let msg = "[Storage] Index::drop_index is not supported".to_owned();
68
69 Err(Error::StorageMsg(msg))
70 }
71}