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        }])
17    }
18
19    fn plan_upsert(&self, p: UpsertParams) -> Result<Vec<SqlPlan>> {
20        Ok(vec![SqlPlan::Upsert {
21            collection: p.collection,
22            engine: EngineType::DocumentStrict,
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        Ok(SqlPlan::Scan {
31            collection: p.collection,
32            alias: p.alias,
33            engine: EngineType::DocumentStrict,
34            filters: p.filters,
35            projection: p.projection,
36            sort_keys: p.sort_keys,
37            limit: p.limit,
38            offset: p.offset,
39            distinct: p.distinct,
40            window_functions: p.window_functions,
41        })
42    }
43
44    fn plan_point_get(&self, p: PointGetParams) -> Result<SqlPlan> {
45        Ok(SqlPlan::PointGet {
46            collection: p.collection,
47            alias: p.alias,
48            engine: EngineType::DocumentStrict,
49            key_column: p.key_column,
50            key_value: p.key_value,
51        })
52    }
53
54    fn plan_update(&self, p: UpdateParams) -> Result<Vec<SqlPlan>> {
55        Ok(vec![SqlPlan::Update {
56            collection: p.collection,
57            engine: EngineType::DocumentStrict,
58            assignments: p.assignments,
59            filters: p.filters,
60            target_keys: p.target_keys,
61            returning: p.returning,
62        }])
63    }
64
65    fn plan_delete(&self, p: DeleteParams) -> Result<Vec<SqlPlan>> {
66        Ok(vec![SqlPlan::Delete {
67            collection: p.collection,
68            engine: EngineType::DocumentStrict,
69            filters: p.filters,
70            target_keys: p.target_keys,
71        }])
72    }
73
74    fn plan_aggregate(&self, p: AggregateParams) -> Result<SqlPlan> {
75        let base_scan = SqlPlan::Scan {
76            collection: p.collection,
77            alias: p.alias,
78            engine: EngineType::DocumentStrict,
79            filters: p.filters,
80            projection: Vec::new(),
81            sort_keys: Vec::new(),
82            limit: None,
83            offset: 0,
84            distinct: false,
85            window_functions: Vec::new(),
86        };
87        Ok(SqlPlan::Aggregate {
88            input: Box::new(base_scan),
89            group_by: p.group_by,
90            aggregates: p.aggregates,
91            having: p.having,
92            limit: p.limit,
93        })
94    }
95}