Skip to main content

nodedb_sql/engine_rules/
document_schemaless.rs

1//! Engine rules for schemaless document collections.
2
3use crate::engine_rules::*;
4use crate::error::Result;
5use crate::types::*;
6
7pub struct SchemalessRules;
8
9impl EngineRules for SchemalessRules {
10    fn plan_insert(&self, p: InsertParams) -> Result<Vec<SqlPlan>> {
11        Ok(vec![SqlPlan::Insert {
12            collection: p.collection,
13            engine: EngineType::DocumentSchemaless,
14            rows: p.rows,
15            column_defaults: p.column_defaults,
16        }])
17    }
18
19    fn plan_upsert(&self, p: UpsertParams) -> Result<Vec<SqlPlan>> {
20        Ok(vec![SqlPlan::Upsert {
21            collection: p.collection,
22            engine: EngineType::DocumentSchemaless,
23            rows: p.rows,
24            column_defaults: p.column_defaults,
25            on_conflict_updates: p.on_conflict_updates,
26        }])
27    }
28
29    fn plan_scan(&self, p: ScanParams) -> Result<SqlPlan> {
30        if let Some(plan) =
31            crate::engine_rules::try_document_index_lookup(&p, EngineType::DocumentSchemaless)
32        {
33            return Ok(plan);
34        }
35        Ok(SqlPlan::Scan {
36            collection: p.collection,
37            alias: p.alias,
38            engine: EngineType::DocumentSchemaless,
39            filters: p.filters,
40            projection: p.projection,
41            sort_keys: p.sort_keys,
42            limit: p.limit,
43            offset: p.offset,
44            distinct: p.distinct,
45            window_functions: p.window_functions,
46        })
47    }
48
49    fn plan_point_get(&self, p: PointGetParams) -> Result<SqlPlan> {
50        Ok(SqlPlan::PointGet {
51            collection: p.collection,
52            alias: p.alias,
53            engine: EngineType::DocumentSchemaless,
54            key_column: p.key_column,
55            key_value: p.key_value,
56        })
57    }
58
59    fn plan_update(&self, p: UpdateParams) -> Result<Vec<SqlPlan>> {
60        Ok(vec![SqlPlan::Update {
61            collection: p.collection,
62            engine: EngineType::DocumentSchemaless,
63            assignments: p.assignments,
64            filters: p.filters,
65            target_keys: p.target_keys,
66            returning: p.returning,
67        }])
68    }
69
70    fn plan_delete(&self, p: DeleteParams) -> Result<Vec<SqlPlan>> {
71        Ok(vec![SqlPlan::Delete {
72            collection: p.collection,
73            engine: EngineType::DocumentSchemaless,
74            filters: p.filters,
75            target_keys: p.target_keys,
76        }])
77    }
78
79    fn plan_aggregate(&self, p: AggregateParams) -> Result<SqlPlan> {
80        let base_scan = SqlPlan::Scan {
81            collection: p.collection,
82            alias: p.alias,
83            engine: EngineType::DocumentSchemaless,
84            filters: p.filters,
85            projection: Vec::new(),
86            sort_keys: Vec::new(),
87            limit: None,
88            offset: 0,
89            distinct: false,
90            window_functions: Vec::new(),
91        };
92        Ok(SqlPlan::Aggregate {
93            input: Box::new(base_scan),
94            group_by: p.group_by,
95            aggregates: p.aggregates,
96            having: p.having,
97            limit: p.limit,
98        })
99    }
100}