Skip to main content

nodedb_sql/engine_rules/
document_strict.rs

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