Skip to main content

clt_database/index_method/
backing_btree.rs

1use crate::sync::Arc;
2
3use crate::{
4    index_method::{
5        IndexMethod, IndexMethodAttachment, IndexMethodConfiguration, IndexMethodCursor,
6        IndexMethodDefinition, BACKING_BTREE_INDEX_METHOD_NAME,
7    },
8    LimboError, Result,
9};
10
11/// Special 'backing_btree' index method which can be used by other custom index methods
12///
13/// Under the hood, it's marked as 'treat_as_btree' which recognized by the tursodb core as a special index method
14/// which should be translated to ordinary btree but also do not explicitly managed by the core
15#[derive(Debug)]
16pub struct BackingBtreeIndexMethod;
17
18#[derive(Debug)]
19pub struct BackingBTreeIndexMethodAttachment(String);
20
21impl IndexMethod for BackingBtreeIndexMethod {
22    fn attach(
23        &self,
24        configuration: &IndexMethodConfiguration,
25    ) -> Result<Arc<dyn IndexMethodAttachment>> {
26        Ok(Arc::new(BackingBTreeIndexMethodAttachment(
27            configuration.index_name.clone(),
28        )))
29    }
30}
31
32impl IndexMethodAttachment for BackingBTreeIndexMethodAttachment {
33    fn definition<'a>(&'a self) -> IndexMethodDefinition<'a> {
34        IndexMethodDefinition {
35            method_name: BACKING_BTREE_INDEX_METHOD_NAME,
36            index_name: &self.0,
37            patterns: &[],
38            backing_btree: true,
39            results_materialized: false,
40        }
41    }
42
43    fn init(&self) -> Result<Box<dyn IndexMethodCursor>> {
44        Err(LimboError::InternalError(
45            "init is not supported for backing_btree index method".to_string(),
46        ))
47    }
48}