gluesql_core/store/
index.rs

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