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

source

pub fn find_enum<'db>(&'db self, name: &str) -> Option<EnumWalker<'db>>

Find an enum by name.

source

pub fn find_model<'db>(&'db self, name: &str) -> Option<ModelWalker<'db>>

Find a model by name.

source

pub fn walk<I>(&self, id: I) -> Walker<'_, I>

Traverse a schema element by id.

source

pub fn walk_enums(&self) -> impl Iterator<Item = EnumWalker<'_>>

Walk all enums in the schema.

source

pub fn walk_models(&self) -> impl Iterator<Item = ModelWalker<'_>> + '_

Walk all the models in the schema.

source

pub fn walk_views(&self) -> impl Iterator<Item = ModelWalker<'_>> + '_

Walk all the views in the schema.

source

pub fn walk_composite_types( &self ) -> impl Iterator<Item = CompositeTypeWalker<'_>> + '_

Walk all the composite types in the schema.

source

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.

source

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.

source

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

source

pub fn new(file: SourceFile, diagnostics: &mut Diagnostics) -> Self

See the docs on ParserDatabase.

source

pub fn ast(&self) -> &SchemaAst

The parsed AST.

source

pub fn enums_count(&self) -> usize

The total number of enums in the schema. This is O(1).

source

pub fn models_count(&self) -> usize

The total number of models in the schema. This is O(1).

source

pub fn source(&self) -> &str

The source file contents.

Trait Implementations§

source§

impl Debug for ParserDatabase

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.