pub struct Walker<'db, I> {
    pub db: &'db ParserDatabase,
    pub id: I,
}
Expand description

A generic walker. Only walkers intantiated with a concrete ID type (I) are useful.

Fields§

§db: &'db ParserDatabase

The parser database being traversed.

§id: I

The identifier of the focused element.

Implementations§

source§

impl<'db> Walker<'db, CompositeTypeId>

source

pub fn composite_type_id(self) -> CompositeTypeId

The ID of the composite type node in the AST.

source

pub fn ast_composite_type(self) -> &'db CompositeType

The composite type node in the AST.

source

pub fn name(self) -> &'db str

The name of the composite type in the schema.

source

pub fn fields( self ) -> impl ExactSizeIterator<Item = CompositeTypeFieldWalker<'db>> + Clone

Iterator over all the fields of the composite type.

source§

impl<'db> Walker<'db, (CompositeTypeId, FieldId)>

source

pub fn ast_field(self) -> &'db Field

The AST node for the field.

source

pub fn composite_type(self) -> CompositeTypeWalker<'db>

The composite type containing the field.

source

pub fn documentation(&self) -> Option<&str>

The optional documentation string of the field.

source

pub fn mapped_name(self) -> Option<&'db str>

The name contained in the @map() attribute of the field, if any.

source

pub fn field_id(self) -> FieldId

The ID of the field in the AST.

source

pub fn name(self) -> &'db str

The name of the field.

source

pub fn arity(self) -> FieldArity

Is the field required, optional or a list?

source

pub fn type(self) -> ScalarFieldType

The type of the field, e.g. String in streetName String?.

source

pub fn scalar_type(self) -> Option<ScalarType>

The type of the field in case it is a scalar type (not an enum, not a composite type).

source

pub fn default_attribute(self) -> Option<&'db Attribute>

The @default() AST attribute on the field, if any.

source

pub fn raw_native_type( self ) -> Option<(&'db str, &'db str, &'db [String], Span)>

(attribute scope, native type name, arguments, span)

For example: @db.Text would translate to (“db”, “Text”, &[], )

source

pub fn default_value(self) -> Option<&'db Expression>

The value expression in the @default attribute.

score Int @default(0)
                   ^
source

pub fn default_mapped_name(self) -> Option<&'db str>

The mapped name of the default value. Always None in composite types at the moment.

name String @default("george", map: "name_default_to_george")
                                    ^^^^^^^^^^^^^^^^^^^^^^^^
source

pub fn database_name(self) -> &'db str

The final database name of the field. See crate docs for explanations on database names.

source§

impl<'db> Walker<'db, EnumId>

source

pub fn name(self) -> &'db str

The name of the enum.

source

pub fn ast_enum(self) -> &'db Enum

The AST node.

source

pub fn database_name(self) -> &'db str

The database name of the enum.

source

pub fn mapped_name(self) -> Option<&'db str>

The mapped name of the enum:

enum Colour {
    RED
    GREEN
    BLUE

    @@map("Color")
          ^^^^^^^
}
source

pub fn values(self) -> impl ExactSizeIterator<Item = EnumValueWalker<'db>>

The values of the enum.

source

pub fn indentation(self) -> IndentationType

How fields are indented in the enum.

source

pub fn newline(self) -> NewlineType

What kind of newlines the enum uses.

source

pub fn schema(self) -> Option<(&'db str, Span)>

The name of the schema the enum belongs to.

@@schema("public")
         ^^^^^^^^
source§

impl<'db> Walker<'db, (EnumId, usize)>

source

pub fn documentation(self) -> Option<&'db str>

The enum documentation

source

pub fn name(self) -> &'db str

The name of the value.

source

pub fn database_name(self) -> &'db str

The database name of the enum.

source

pub fn mapped_name(self) -> Option<&'db str>

The mapped name of the value:

enum Colour {
    RED @map("scarlet")
    GREEN @map("salad")
               ^^^^^^^
    BLUE @map("schmurf")
}
source§

impl<'db> Walker<'db, (ModelId, FieldId)>

source

pub fn ast_field(self) -> &'db Field

The AST node for the field.

source

pub fn name(self) -> &'db str

The field name.

source

pub fn model(self) -> ModelWalker<'db>

Traverse the field’s parent model.

source

pub fn refine(self) -> RefinedFieldWalker<'db>

Find out which kind of field this is.

source§

impl<'db> Walker<'db, ModelId>

source

pub fn name(self) -> &'db str

The name of the model.

source

pub fn fields(self) -> impl ExactSizeIterator<Item = FieldWalker<'db>> + Clone

Traverse the fields of the models in the order they were defined.

source

pub fn field_is_indexed_for_autoincrement(self, field_id: FieldId) -> bool

Whether MySQL would consider the field indexed for autoincrement purposes.

source

pub fn field_is_single_pk(self, field: FieldId) -> bool

Whether the field is the whole primary key. Will match @id and @@id([fieldName]).

source

pub fn field_is_part_of_a_compound_pk(self, field: FieldId) -> bool

Is the field part of a compound primary key.

source

pub fn model_id(self) -> ModelId

The ID of the model in the db

source

pub fn ast_model(self) -> &'db Model

The AST node.

source

pub fn is_ignored(self) -> bool

Model has the @@ignore attribute.

source

pub fn database_name(self) -> &'db str

The name of the database table the model points to.

source

pub fn has_single_id_field(self) -> bool

Used in validation. True only if the model has a single field id.

source

pub fn mapped_name(self) -> Option<&'db str>

The name in the @@map attribute.

source

pub fn primary_key(self) -> Option<PrimaryKeyWalker<'db>>

The primary key of the model, if defined.

source

pub fn scalar_fields( self ) -> impl Iterator<Item = ScalarFieldWalker<'db>> + Clone

Iterate all the scalar fields in a given model in the order they were defined.

source

pub fn unique_criterias(self) -> impl Iterator<Item = UniqueCriteriaWalker<'db>>

All unique criterias of the model; consisting of the primary key and unique indexes, if set.

source

pub fn required_unique_criterias( self ) -> impl Iterator<Item = UniqueCriteriaWalker<'db>>

All required unique criterias of the model; consisting of the primary key and unique indexes, if set.

source

pub fn indexes(self) -> impl Iterator<Item = IndexWalker<'db>>

Iterate all the indexes in the model in the order they were defined.

source

pub fn relation_fields( self ) -> impl Iterator<Item = RelationFieldWalker<'db>> + Clone + 'db

All (concrete) relation fields of the model.

source

pub fn relations_from(self) -> impl Iterator<Item = RelationWalker<'db>>

All relations that start from this model.

source

pub fn relations_to(self) -> impl Iterator<Item = RelationWalker<'db>>

All relations that reference this model.

source

pub fn inline_relations_from( self ) -> impl Iterator<Item = InlineRelationWalker<'db>>

1:n and 1:1 relations that start from this model.

source

pub fn complete_inline_relations_from( self ) -> impl Iterator<Item = CompleteInlineRelationWalker<'db>>

1:n and 1:1 relations, starting from this model and having both sides defined.

source

pub fn indentation(self) -> IndentationType

How fields and arguments are indented in the model.

source

pub fn newline(self) -> NewlineType

What kind of newlines the model uses.

source

pub fn schema(self) -> Option<(&'db str, Span)>

The name of the schema the model belongs to.

@@schema("public")
         ^^^^^^^^
source

pub fn schema_name(self) -> Option<&'db str>

The name of the schema the model belongs to.

@@schema("public")
         ^^^^^^^^
source§

impl<'db> Walker<'db, ManyToManyRelationId>

source

pub fn is_self_relation(self) -> bool

Is this a many-to-many self-relation?

source

pub fn model_a(self) -> ModelWalker<'db>

The model which comes first in the alphabetical order.

source

pub fn model_b(self) -> ModelWalker<'db>

The model which comes after model a in the alphabetical order.

source

pub fn field_a(self) -> RelationFieldWalker<'db>

The field that defines the relation in model a.

source

pub fn field_b(self) -> RelationFieldWalker<'db>

The field that defines the relation in model b.

source

pub fn as_relation(self) -> RelationWalker<'db>

Traverse this relation as a generic relation.

source

pub fn relation_name(self) -> RelationName<'db>

The name of the relation.

source

pub fn column_a_name(self) -> &'static str

The name of the column pointing to model A in the implicit join table.

source

pub fn column_b_name(self) -> &'static str

The name of the column pointing to model B in the implicit join table.

source

pub fn table_name(self) -> ImplicitManyToManyRelationTableName<'db>

A representation of the table/collection implicit in this relation.

source§

impl<'db> Walker<'db, RelationId>

source

pub fn models(self) -> [ModelId; 2]

The models at each end of the relation. [model A, model B]. Can be the same model twice.

source

pub fn relation_fields(self) -> impl Iterator<Item = RelationFieldWalker<'db>>

The relation fields that define the relation. A then B.

source

pub fn is_ignored(self) -> bool

Is any field part of the relation ignored (@ignore) or unsupported?

source

pub fn is_self_relation(self) -> bool

Is this a relation where both ends are the same model?

source

pub fn refine(self) -> RefinedRelationWalker<'db>

Converts the walker to either an implicit many to many, or a inline relation walker gathering 1:1 and 1:n relations.

source

pub fn explicit_relation_name(self) -> Option<&'db str>

The relation name in the schema.

myField OtherModel @relation("thisModelToOtherModel", fields: [fkfield], references: [id])
//                           ^^^^^^^^^^^^^^^^^^^^^^^
source

pub fn relation_name(self) -> RelationName<'db>

The relation name, explicit or inferred.

posts Post[] @relation("UserPosts")
                       ^^^^^^^^^^^
source§

impl<'db> Walker<'db, RelationFieldId>

source

pub fn one_side_is_view(self) -> bool

The relation starts or ends to a view.

source

pub fn mapped_name(self) -> Option<&'db str>

The foreign key name of the relation (@relation(map: ...)).

source

pub fn name(self) -> &'db str

The field name.

source

pub fn ast_field(self) -> &'db Field

The AST node of the field.

source

pub fn explicit_on_delete(self) -> Option<ReferentialAction>

The onDelete argument on the relation.

source

pub fn explicit_on_delete_span(self) -> Option<Span>

The onDelete argument on the relation.

source

pub fn explicit_on_update(self) -> Option<ReferentialAction>

The onUpdate argument on the relation.

source

pub fn explicit_on_update_span(self) -> Option<Span>

The onUpdate argument on the relation.

source

pub fn explicit_relation_name(self) -> Option<&'db str>

The relation name explicitly written in the schema source.

source

pub fn is_ignored(self) -> bool

Is there an @ignore attribute on the field?

source

pub fn is_required(self) -> bool

Is the field required? (not optional, not list)

source

pub fn model(self) -> ModelWalker<'db>

The model containing the field.

source

pub fn opposite_relation_field(self) -> Option<RelationFieldWalker<'db>>

A valid relation is defined by two relation fields. This method returns the other relation field in the same relation.

source

pub fn relation_attribute(self) -> Option<&'db Attribute>

The @relation attribute in the field AST.

source

pub fn references_model(self, other: ModelId) -> bool

Does the relation field reference the passed in model?

source

pub fn related_model(self) -> ModelWalker<'db>

The model referenced by the relation.

source

pub fn referenced_fields( self ) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>>>

The fields in the @relation(references: ...) argument.

source

pub fn relation(self) -> RelationWalker<'db>

The relation this field is part of.

source

pub fn relation_name(self) -> RelationName<'db>

The name of the relation. Either uses the name (or default) argument, or generates an implicit name.

source

pub fn referential_arity(self) -> FieldArity

The arity to enforce, based on the arity of the fields. If any referencing field is required, this will be required.

Prisma allows setting the relation field as optional, even if one of the underlying scalar fields is required. For the purpose of referential actions, we count the relation field required if any of the underlying fields is required.

source

pub fn references_singular_id_field(self) -> bool

Used for validation.

source

pub fn referencing_fields( self ) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>> + Clone>

The fields in the fields: [...] argument in the forward relation field.

source

pub fn fields( self ) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>> + Clone>

The fields in the fields: [...] argument in the forward relation field.

source§

impl<'db> Walker<'db, ScalarFieldId>

source

pub fn field_id(self) -> FieldId

The ID of the field node in the AST.

source

pub fn ast_field(self) -> &'db Field

The field node in the AST.

source

pub fn is_unique(self) -> bool

Is this field unique? This method will return true if:

  • The field has an @id or @unique attribute.
  • There is an @@id or @@unique on the model that contains only this field.
source

pub fn name(self) -> &'db str

The name of the field.

source

pub fn default_attribute(self) -> Option<&'db Attribute>

The @default() AST attribute on the field, if any.

source

pub fn database_name(self) -> &'db str

The final database name of the field. See crate docs for explanations on database names.

source

pub fn is_autoincrement(self) -> bool

Does the field have an @default(autoincrement()) attribute?

source

pub fn is_single_pk(self) -> bool

Does the field define a primary key by its own.

source

pub fn is_part_of_a_compound_pk(self) -> bool

Is the field part of a compound primary key.

source

pub fn is_ignored(self) -> bool

Is there an @ignore attribute on the field?

source

pub fn is_optional(self) -> bool

Is the field optional / nullable?

source

pub fn is_list(self) -> bool

Is the field a list

source

pub fn is_updated_at(self) -> bool

Is there an @updatedAt attribute on the field?

source

pub fn field_type_as_enum(self) -> Option<EnumWalker<'db>>

Is this field’s type an enum? If yes, walk the enum.

source

pub fn mapped_name(self) -> Option<&'db str>

The name in the @map(<name>) attribute.

source

pub fn model(self) -> ModelWalker<'db>

The model that contains the field.

source

pub fn raw_native_type( self ) -> Option<(&'db str, &'db str, &'db [String], Span)>

(attribute scope, native type name, arguments, span)

For example: @db.Text would translate to (“db”, “Text”, &[], )

source

pub fn is_unsupported(self) -> bool

Is the type of the field Unsupported("...")?

source

pub fn default_value(self) -> Option<DefaultValueWalker<'db>>

The @default() attribute of the field, if any.

source

pub fn scalar_field_type(self) -> ScalarFieldType

The type of the field.

source

pub fn scalar_type(self) -> Option<ScalarType>

The type of the field in case it is a scalar type (not an enum, not a composite type).

source§

impl<'db, I> Walker<'db, I>

source

pub fn walk<J>(self, other: J) -> Walker<'db, J>

Traverse something else in the same schema.

Trait Implementations§

source§

impl<'db, I: Clone> Clone for Walker<'db, I>

source§

fn clone(&self) -> Walker<'db, I>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'db> From<Walker<'db, (CompositeTypeId, FieldId)>> for IndexFieldWalker<'db>

source§

fn from(cf: CompositeTypeFieldWalker<'db>) -> Self

Converts to this type from the input type.
source§

impl<'db> From<Walker<'db, (CompositeTypeId, FieldId)>> for TypedFieldWalker<'db>

source§

fn from(w: CompositeTypeFieldWalker<'db>) -> Self

Converts to this type from the input type.
source§

impl<'db> From<Walker<'db, RelationFieldId>> for FieldWalker<'db>

source§

fn from(w: RelationFieldWalker<'db>) -> Self

Converts to this type from the input type.
source§

impl<'db> From<Walker<'db, ScalarFieldId>> for IndexFieldWalker<'db>

source§

fn from(sf: ScalarFieldWalker<'db>) -> Self

Converts to this type from the input type.
source§

impl<'db> From<Walker<'db, ScalarFieldId>> for TypedFieldWalker<'db>

source§

fn from(w: ScalarFieldWalker<'db>) -> Self

Converts to this type from the input type.
source§

impl<'db> From<Walker<'db, ScalarFieldId>> for FieldWalker<'db>

source§

fn from(w: ScalarFieldWalker<'db>) -> Self

Converts to this type from the input type.
source§

impl<'db, I> PartialEq for Walker<'db, I>where I: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'db, I: Copy> Copy for Walker<'db, I>

Auto Trait Implementations§

§

impl<'db, I> RefUnwindSafe for Walker<'db, I>where I: RefUnwindSafe,

§

impl<'db, I> Send for Walker<'db, I>where I: Send,

§

impl<'db, I> Sync for Walker<'db, I>where I: Sync,

§

impl<'db, I> Unpin for Walker<'db, I>where I: Unpin,

§

impl<'db, I> UnwindSafe for Walker<'db, I>where I: UnwindSafe,

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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.