pub struct SchemaSnapshot { /* private fields */ }Expand description
Every class schema, as of one point in time.
Implementations§
Source§impl SchemaSnapshot
impl SchemaSnapshot
Sourcepub async fn load<S: StorageAdapter>(storage: &S) -> Result<Self, ParseError>
pub async fn load<S: StorageAdapter>(storage: &S) -> Result<Self, ParseError>
Load every schema from storage. Called once per request.
Sourcepub fn from_classes(classes: Vec<ClassSchema>) -> Self
pub fn from_classes(classes: Vec<ClassSchema>) -> Self
Build a snapshot from an already-loaded list. Cheap, and the constructor tests use.
pub fn get(&self, class_name: &str) -> Option<&ClassSchema>
Sourcepub fn contains(&self, class_name: &str) -> bool
pub fn contains(&self, class_name: &str) -> bool
Does this class exist? Upstream’s classExists, which decides whether a count short
circuits to zero rather than reaching the adapter (DatabaseController.js:1524-1527).
Sourcepub fn get_or_default(&self, class_name: &str) -> Cow<'_, ClassSchema>
pub fn get_or_default(&self, class_name: &str) -> Cow<'_, ClassSchema>
The schema to read a class under.
A missing class behaves as {fields: {}} rather than as an error
(DatabaseController.js:1422-1432), so a query against a class nobody has written yet
returns nothing instead of failing. Note that this is not Self::resolve_for_write:
the read fallback has no default columns at all, which is what makes every sort key on a
non-existent class get dropped.
Sourcepub fn resolve_for_write(&self, class_name: &str) -> ClassSchema
pub fn resolve_for_write(&self, class_name: &str) -> ClassSchema
The schema to write a class under.
A missing class resolves to the injected default schema, matching enforceClassExists
followed by getOneSchema on the create path (DatabaseController.js:939-940). The
difference from Self::get_or_default is load bearing: without _Role.users typed as a
Relation, the first write to a role infers it from whatever it happens to carry.
Sourcepub fn clp(&self, class_name: &str) -> Option<&ClassLevelPermissions>
pub fn clp(&self, class_name: &str) -> Option<&ClassLevelPermissions>
The class-level permissions for a class.
None means the class has no CLP block, which is unrestricted, not denied. Every
caller has to spell that out; see parse_rust_core::clp.
Sourcepub fn insert(&mut self, schema: ClassSchema)
pub fn insert(&mut self, schema: ClassSchema)
Insert or replace a class. Used after a write reserves a new field, and by tests.
Trait Implementations§
Source§impl Clone for SchemaSnapshot
impl Clone for SchemaSnapshot
Source§fn clone(&self) -> SchemaSnapshot
fn clone(&self) -> SchemaSnapshot
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more