Skip to main content

cratestack_sql/descriptor/
model_impls.rs

1//! `ReadSource` / `WriteSource` impls for
2//! [`ModelDescriptor`](super::ModelDescriptor). Pulled into its own
3//! file to keep `descriptor/mod.rs` under the 200-LoC ceiling.
4//!
5//! The impls are pure delegation — each trait method returns the
6//! identically-named `ModelDescriptor` field. They exist so the
7//! upcoming view-aware read builders can take either
8//! `&ModelDescriptor<M, PK>` or `&ViewDescriptor<V, PK>` through a
9//! shared trait bound without forcing the existing model-specific
10//! call sites to change at the same time.
11
12use cratestack_core::ModelEventKind;
13use cratestack_policy::ReadPolicy;
14
15use super::{CreateDefault, ModelColumn, ModelDescriptor, ReadSource, WriteSource};
16
17impl<M, PK> ReadSource<M, PK> for ModelDescriptor<M, PK> {
18    fn schema_name(&self) -> &'static str {
19        self.schema_name
20    }
21    fn table_name(&self) -> &'static str {
22        self.table_name
23    }
24    fn columns(&self) -> &'static [ModelColumn] {
25        self.columns
26    }
27    fn primary_key(&self) -> &'static str {
28        self.primary_key
29    }
30    fn allowed_fields(&self) -> &'static [&'static str] {
31        self.allowed_fields
32    }
33    fn allowed_includes(&self) -> &'static [&'static str] {
34        self.allowed_includes
35    }
36    fn allowed_sorts(&self) -> &'static [&'static str] {
37        self.allowed_sorts
38    }
39    fn read_allow_policies(&self) -> &'static [ReadPolicy] {
40        self.read_allow_policies
41    }
42    fn read_deny_policies(&self) -> &'static [ReadPolicy] {
43        self.read_deny_policies
44    }
45    fn detail_allow_policies(&self) -> &'static [ReadPolicy] {
46        self.detail_allow_policies
47    }
48    fn detail_deny_policies(&self) -> &'static [ReadPolicy] {
49        self.detail_deny_policies
50    }
51    fn soft_delete_column(&self) -> Option<&'static str> {
52        self.soft_delete_column
53    }
54    fn select_projection(&self) -> String {
55        ModelDescriptor::select_projection(self)
56    }
57    fn select_projection_subset(&self, columns: &[&str]) -> String {
58        ModelDescriptor::select_projection_subset(self, columns)
59    }
60}
61
62impl<M, PK> WriteSource<M, PK> for ModelDescriptor<M, PK> {
63    fn create_allow_policies(&self) -> &'static [ReadPolicy] {
64        self.create_allow_policies
65    }
66    fn create_deny_policies(&self) -> &'static [ReadPolicy] {
67        self.create_deny_policies
68    }
69    fn update_allow_policies(&self) -> &'static [ReadPolicy] {
70        self.update_allow_policies
71    }
72    fn update_deny_policies(&self) -> &'static [ReadPolicy] {
73        self.update_deny_policies
74    }
75    fn delete_allow_policies(&self) -> &'static [ReadPolicy] {
76        self.delete_allow_policies
77    }
78    fn delete_deny_policies(&self) -> &'static [ReadPolicy] {
79        self.delete_deny_policies
80    }
81    fn create_defaults(&self) -> &'static [CreateDefault] {
82        self.create_defaults
83    }
84    fn emitted_events(&self) -> &'static [ModelEventKind] {
85        self.emitted_events
86    }
87    fn version_column(&self) -> Option<&'static str> {
88        self.version_column
89    }
90    fn audit_enabled(&self) -> bool {
91        self.audit_enabled
92    }
93    fn pii_columns(&self) -> &'static [&'static str] {
94        self.pii_columns
95    }
96    fn sensitive_columns(&self) -> &'static [&'static str] {
97        self.sensitive_columns
98    }
99    fn retention_days(&self) -> Option<u32> {
100        self.retention_days
101    }
102    fn upsert_update_columns(&self) -> &'static [&'static str] {
103        self.upsert_update_columns
104    }
105}