Struct parser_database::ParserDatabase
source · pub struct ParserDatabase { /* private fields */ }
Expand description
ParserDatabase is a container for a Schema AST, together with information
gathered during schema validation. Each validation step enriches the
database with information that can be used to work with the schema, without
changing the AST. Instantiating with ParserDatabase::new()
will perform a
number of validations and make sure the schema makes sense, but it cannot
fail. In case the schema is invalid, diagnostics will be created and the
resolved information will be incomplete.
Validations are carried out in the following order:
- The AST is walked a first time to resolve names: to each relevant identifier, we attach an ID that can be used to reference the corresponding item (model, enum, field, …)
- The AST is walked a second time to resolve types. For each field and each type alias, we look at the type identifier and resolve what it refers to.
- The AST is walked a third time to validate attributes on models and fields.
- Global validations are then performed on the mostly validated schema. Currently only index name collisions.
Implementations§
source§impl ParserDatabase
impl ParserDatabase
sourcepub fn find_enum<'db>(&'db self, name: &str) -> Option<EnumWalker<'db>>
pub fn find_enum<'db>(&'db self, name: &str) -> Option<EnumWalker<'db>>
Find an enum by name.
sourcepub fn find_model<'db>(&'db self, name: &str) -> Option<ModelWalker<'db>>
pub fn find_model<'db>(&'db self, name: &str) -> Option<ModelWalker<'db>>
Find a model by name.
sourcepub fn walk_enums(&self) -> impl Iterator<Item = EnumWalker<'_>>
pub fn walk_enums(&self) -> impl Iterator<Item = EnumWalker<'_>>
Walk all enums in the schema.
sourcepub fn walk_models(&self) -> impl Iterator<Item = ModelWalker<'_>> + '_
pub fn walk_models(&self) -> impl Iterator<Item = ModelWalker<'_>> + '_
Walk all the models in the schema.
sourcepub fn walk_views(&self) -> impl Iterator<Item = ModelWalker<'_>> + '_
pub fn walk_views(&self) -> impl Iterator<Item = ModelWalker<'_>> + '_
Walk all the views in the schema.
sourcepub fn walk_composite_types(
&self
) -> impl Iterator<Item = CompositeTypeWalker<'_>> + '_
pub fn walk_composite_types( &self ) -> impl Iterator<Item = CompositeTypeWalker<'_>> + '_
Walk all the composite types in the schema.
sourcepub fn walk_scalar_field_defaults_with_unknown_function(
&self
) -> impl Iterator<Item = DefaultValueWalker<'_>>
pub fn walk_scalar_field_defaults_with_unknown_function( &self ) -> impl Iterator<Item = DefaultValueWalker<'_>>
Walk all scalar field defaults with a function not part of the common ones.
sourcepub fn walk_relations(
&self
) -> impl ExactSizeIterator<Item = RelationWalker<'_>> + Clone + '_
pub fn walk_relations( &self ) -> impl ExactSizeIterator<Item = RelationWalker<'_>> + Clone + '_
Walk all the relations in the schema. A relation may be defined by one or two fields; in both cases, it is still a single relation.
sourcepub fn walk_complete_inline_relations(
&self
) -> impl Iterator<Item = CompleteInlineRelationWalker<'_>> + '_
pub fn walk_complete_inline_relations( &self ) -> impl Iterator<Item = CompleteInlineRelationWalker<'_>> + '_
Iterate all complete relations that are not many to many and are correctly defined from both sides.
source§impl ParserDatabase
impl ParserDatabase
sourcepub fn new(file: SourceFile, diagnostics: &mut Diagnostics) -> Self
pub fn new(file: SourceFile, diagnostics: &mut Diagnostics) -> Self
See the docs on ParserDatabase.
sourcepub fn enums_count(&self) -> usize
pub fn enums_count(&self) -> usize
The total number of enums in the schema. This is O(1).
sourcepub fn models_count(&self) -> usize
pub fn models_count(&self) -> usize
The total number of models in the schema. This is O(1).