Struct parser_database::walkers::Walker
source · 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>
impl<'db> Walker<'db, CompositeTypeId>
sourcepub fn composite_type_id(self) -> CompositeTypeId
pub fn composite_type_id(self) -> CompositeTypeId
The ID of the composite type node in the AST.
sourcepub fn ast_composite_type(self) -> &'db CompositeType
pub fn ast_composite_type(self) -> &'db CompositeType
The composite type node in the AST.
sourcepub fn fields(
self
) -> impl ExactSizeIterator<Item = CompositeTypeFieldWalker<'db>> + Clone
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)>
impl<'db> Walker<'db, (CompositeTypeId, FieldId)>
sourcepub fn composite_type(self) -> CompositeTypeWalker<'db>
pub fn composite_type(self) -> CompositeTypeWalker<'db>
The composite type containing the field.
sourcepub fn documentation(&self) -> Option<&str>
pub fn documentation(&self) -> Option<&str>
The optional documentation string of the field.
sourcepub fn mapped_name(self) -> Option<&'db str>
pub fn mapped_name(self) -> Option<&'db str>
The name contained in the @map()
attribute of the field, if any.
sourcepub fn arity(self) -> FieldArity
pub fn arity(self) -> FieldArity
Is the field required, optional or a list?
sourcepub fn type(self) -> ScalarFieldType
pub fn type(self) -> ScalarFieldType
The type of the field, e.g. String
in streetName String?
.
sourcepub fn scalar_type(self) -> Option<ScalarType>
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).
sourcepub fn default_attribute(self) -> Option<&'db Attribute>
pub fn default_attribute(self) -> Option<&'db Attribute>
The @default()
AST attribute on the field, if any.
sourcepub fn raw_native_type(
self
) -> Option<(&'db str, &'db str, &'db [String], Span)>
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”, &[],
sourcepub fn default_value(self) -> Option<&'db Expression>
pub fn default_value(self) -> Option<&'db Expression>
The value expression in the @default
attribute.
score Int @default(0)
^
sourcepub fn default_mapped_name(self) -> Option<&'db str>
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")
^^^^^^^^^^^^^^^^^^^^^^^^
sourcepub fn database_name(self) -> &'db str
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>
impl<'db> Walker<'db, EnumId>
sourcepub fn database_name(self) -> &'db str
pub fn database_name(self) -> &'db str
The database name of the enum.
sourcepub fn mapped_name(self) -> Option<&'db str>
pub fn mapped_name(self) -> Option<&'db str>
The mapped name of the enum:
enum Colour {
RED
GREEN
BLUE
@@map("Color")
^^^^^^^
}
sourcepub fn values(self) -> impl ExactSizeIterator<Item = EnumValueWalker<'db>>
pub fn values(self) -> impl ExactSizeIterator<Item = EnumValueWalker<'db>>
The values of the enum.
sourcepub fn indentation(self) -> IndentationType
pub fn indentation(self) -> IndentationType
How fields are indented in the enum.
sourcepub fn newline(self) -> NewlineType
pub fn newline(self) -> NewlineType
What kind of newlines the enum uses.
source§impl<'db> Walker<'db, (EnumId, usize)>
impl<'db> Walker<'db, (EnumId, usize)>
sourcepub fn documentation(self) -> Option<&'db str>
pub fn documentation(self) -> Option<&'db str>
The enum documentation
sourcepub fn database_name(self) -> &'db str
pub fn database_name(self) -> &'db str
The database name of the enum.
sourcepub fn mapped_name(self) -> Option<&'db str>
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>
impl<'db> Walker<'db, ModelId>
sourcepub fn fields(self) -> impl ExactSizeIterator<Item = FieldWalker<'db>> + Clone
pub fn fields(self) -> impl ExactSizeIterator<Item = FieldWalker<'db>> + Clone
Traverse the fields of the models in the order they were defined.
sourcepub fn field_is_indexed_for_autoincrement(self, field_id: FieldId) -> bool
pub fn field_is_indexed_for_autoincrement(self, field_id: FieldId) -> bool
Whether MySQL would consider the field indexed for autoincrement purposes.
sourcepub fn field_is_single_pk(self, field: FieldId) -> bool
pub fn field_is_single_pk(self, field: FieldId) -> bool
Whether the field is the whole primary key. Will match @id
and @@id([fieldName])
.
sourcepub fn field_is_part_of_a_compound_pk(self, field: FieldId) -> bool
pub fn field_is_part_of_a_compound_pk(self, field: FieldId) -> bool
Is the field part of a compound primary key.
sourcepub fn is_ignored(self) -> bool
pub fn is_ignored(self) -> bool
Model has the @@ignore attribute.
sourcepub fn database_name(self) -> &'db str
pub fn database_name(self) -> &'db str
The name of the database table the model points to.
sourcepub fn has_single_id_field(self) -> bool
pub fn has_single_id_field(self) -> bool
Used in validation. True only if the model has a single field id.
sourcepub fn mapped_name(self) -> Option<&'db str>
pub fn mapped_name(self) -> Option<&'db str>
The name in the @@map attribute.
sourcepub fn primary_key(self) -> Option<PrimaryKeyWalker<'db>>
pub fn primary_key(self) -> Option<PrimaryKeyWalker<'db>>
The primary key of the model, if defined.
sourcepub fn scalar_fields(
self
) -> impl Iterator<Item = ScalarFieldWalker<'db>> + Clone
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.
sourcepub fn unique_criterias(self) -> impl Iterator<Item = UniqueCriteriaWalker<'db>>
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.
sourcepub fn required_unique_criterias(
self
) -> impl Iterator<Item = UniqueCriteriaWalker<'db>>
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.
sourcepub fn indexes(self) -> impl Iterator<Item = IndexWalker<'db>>
pub fn indexes(self) -> impl Iterator<Item = IndexWalker<'db>>
Iterate all the indexes in the model in the order they were defined.
sourcepub fn relation_fields(
self
) -> impl Iterator<Item = RelationFieldWalker<'db>> + Clone + 'db
pub fn relation_fields( self ) -> impl Iterator<Item = RelationFieldWalker<'db>> + Clone + 'db
All (concrete) relation fields of the model.
sourcepub fn relations_from(self) -> impl Iterator<Item = RelationWalker<'db>>
pub fn relations_from(self) -> impl Iterator<Item = RelationWalker<'db>>
All relations that start from this model.
sourcepub fn relations_to(self) -> impl Iterator<Item = RelationWalker<'db>>
pub fn relations_to(self) -> impl Iterator<Item = RelationWalker<'db>>
All relations that reference this model.
sourcepub fn inline_relations_from(
self
) -> impl Iterator<Item = InlineRelationWalker<'db>>
pub fn inline_relations_from( self ) -> impl Iterator<Item = InlineRelationWalker<'db>>
1:n and 1:1 relations that start from this model.
sourcepub fn complete_inline_relations_from(
self
) -> impl Iterator<Item = CompleteInlineRelationWalker<'db>>
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.
sourcepub fn indentation(self) -> IndentationType
pub fn indentation(self) -> IndentationType
How fields and arguments are indented in the model.
sourcepub fn newline(self) -> NewlineType
pub fn newline(self) -> NewlineType
What kind of newlines the model uses.
sourcepub fn schema(self) -> Option<(&'db str, Span)>
pub fn schema(self) -> Option<(&'db str, Span)>
The name of the schema the model belongs to.
@@schema("public")
^^^^^^^^
sourcepub fn schema_name(self) -> Option<&'db str>
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>
impl<'db> Walker<'db, ManyToManyRelationId>
sourcepub fn is_self_relation(self) -> bool
pub fn is_self_relation(self) -> bool
Is this a many-to-many self-relation?
sourcepub fn model_a(self) -> ModelWalker<'db>
pub fn model_a(self) -> ModelWalker<'db>
The model which comes first in the alphabetical order.
sourcepub fn model_b(self) -> ModelWalker<'db>
pub fn model_b(self) -> ModelWalker<'db>
The model which comes after model a in the alphabetical order.
sourcepub fn field_a(self) -> RelationFieldWalker<'db>
pub fn field_a(self) -> RelationFieldWalker<'db>
The field that defines the relation in model a.
sourcepub fn field_b(self) -> RelationFieldWalker<'db>
pub fn field_b(self) -> RelationFieldWalker<'db>
The field that defines the relation in model b.
sourcepub fn as_relation(self) -> RelationWalker<'db>
pub fn as_relation(self) -> RelationWalker<'db>
Traverse this relation as a generic relation.
sourcepub fn relation_name(self) -> RelationName<'db>
pub fn relation_name(self) -> RelationName<'db>
The name of the relation.
sourcepub fn column_a_name(self) -> &'static str
pub fn column_a_name(self) -> &'static str
The name of the column pointing to model A in the implicit join table.
sourcepub fn column_b_name(self) -> &'static str
pub fn column_b_name(self) -> &'static str
The name of the column pointing to model B in the implicit join table.
sourcepub fn table_name(self) -> ImplicitManyToManyRelationTableName<'db>
pub fn table_name(self) -> ImplicitManyToManyRelationTableName<'db>
A representation of the table/collection implicit in this relation.
source§impl<'db> Walker<'db, RelationId>
impl<'db> Walker<'db, RelationId>
sourcepub fn models(self) -> [ModelId; 2]
pub fn models(self) -> [ModelId; 2]
The models at each end of the relation. [model A, model B]. Can be the same model twice.
sourcepub fn relation_fields(self) -> impl Iterator<Item = RelationFieldWalker<'db>>
pub fn relation_fields(self) -> impl Iterator<Item = RelationFieldWalker<'db>>
The relation fields that define the relation. A then B.
sourcepub fn is_ignored(self) -> bool
pub fn is_ignored(self) -> bool
Is any field part of the relation ignored (@ignore
) or unsupported?
sourcepub fn is_self_relation(self) -> bool
pub fn is_self_relation(self) -> bool
Is this a relation where both ends are the same model?
sourcepub fn refine(self) -> RefinedRelationWalker<'db>
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.
sourcepub fn explicit_relation_name(self) -> Option<&'db str>
pub fn explicit_relation_name(self) -> Option<&'db str>
The relation name in the schema.
myField OtherModel @relation("thisModelToOtherModel", fields: [fkfield], references: [id])
// ^^^^^^^^^^^^^^^^^^^^^^^
sourcepub fn relation_name(self) -> RelationName<'db>
pub fn relation_name(self) -> RelationName<'db>
The relation name, explicit or inferred.
posts Post[] @relation("UserPosts")
^^^^^^^^^^^
source§impl<'db> Walker<'db, RelationFieldId>
impl<'db> Walker<'db, RelationFieldId>
sourcepub fn one_side_is_view(self) -> bool
pub fn one_side_is_view(self) -> bool
The relation starts or ends to a view.
sourcepub fn mapped_name(self) -> Option<&'db str>
pub fn mapped_name(self) -> Option<&'db str>
The foreign key name of the relation (@relation(map: ...)
).
sourcepub fn explicit_on_delete(self) -> Option<ReferentialAction>
pub fn explicit_on_delete(self) -> Option<ReferentialAction>
The onDelete argument on the relation.
sourcepub fn explicit_on_delete_span(self) -> Option<Span>
pub fn explicit_on_delete_span(self) -> Option<Span>
The onDelete argument on the relation.
sourcepub fn explicit_on_update(self) -> Option<ReferentialAction>
pub fn explicit_on_update(self) -> Option<ReferentialAction>
The onUpdate argument on the relation.
sourcepub fn explicit_on_update_span(self) -> Option<Span>
pub fn explicit_on_update_span(self) -> Option<Span>
The onUpdate argument on the relation.
sourcepub fn explicit_relation_name(self) -> Option<&'db str>
pub fn explicit_relation_name(self) -> Option<&'db str>
The relation name explicitly written in the schema source.
sourcepub fn is_ignored(self) -> bool
pub fn is_ignored(self) -> bool
Is there an @ignore
attribute on the field?
sourcepub fn is_required(self) -> bool
pub fn is_required(self) -> bool
Is the field required? (not optional, not list)
sourcepub fn model(self) -> ModelWalker<'db>
pub fn model(self) -> ModelWalker<'db>
The model containing the field.
sourcepub fn opposite_relation_field(self) -> Option<RelationFieldWalker<'db>>
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.
sourcepub fn relation_attribute(self) -> Option<&'db Attribute>
pub fn relation_attribute(self) -> Option<&'db Attribute>
The @relation
attribute in the field AST.
sourcepub fn references_model(self, other: ModelId) -> bool
pub fn references_model(self, other: ModelId) -> bool
Does the relation field reference the passed in model?
The model referenced by the relation.
sourcepub fn referenced_fields(
self
) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>>>
pub fn referenced_fields( self ) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>>>
The fields in the @relation(references: ...)
argument.
sourcepub fn relation(self) -> RelationWalker<'db>
pub fn relation(self) -> RelationWalker<'db>
The relation this field is part of.
sourcepub fn relation_name(self) -> RelationName<'db>
pub fn relation_name(self) -> RelationName<'db>
The name of the relation. Either uses the name
(or default) argument,
or generates an implicit name.
sourcepub fn referential_arity(self) -> FieldArity
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.
sourcepub fn references_singular_id_field(self) -> bool
pub fn references_singular_id_field(self) -> bool
Used for validation.
sourcepub fn referencing_fields(
self
) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>> + Clone>
pub fn referencing_fields( self ) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>> + Clone>
The fields in the fields: [...]
argument in the forward relation field.
sourcepub fn fields(
self
) -> Option<impl ExactSizeIterator<Item = ScalarFieldWalker<'db>> + Clone>
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>
impl<'db> Walker<'db, ScalarFieldId>
sourcepub fn is_unique(self) -> bool
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.
sourcepub fn default_attribute(self) -> Option<&'db Attribute>
pub fn default_attribute(self) -> Option<&'db Attribute>
The @default()
AST attribute on the field, if any.
sourcepub fn database_name(self) -> &'db str
pub fn database_name(self) -> &'db str
The final database name of the field. See crate docs for explanations on database names.
sourcepub fn is_autoincrement(self) -> bool
pub fn is_autoincrement(self) -> bool
Does the field have an @default(autoincrement())
attribute?
sourcepub fn is_single_pk(self) -> bool
pub fn is_single_pk(self) -> bool
Does the field define a primary key by its own.
sourcepub fn is_part_of_a_compound_pk(self) -> bool
pub fn is_part_of_a_compound_pk(self) -> bool
Is the field part of a compound primary key.
sourcepub fn is_ignored(self) -> bool
pub fn is_ignored(self) -> bool
Is there an @ignore
attribute on the field?
sourcepub fn is_optional(self) -> bool
pub fn is_optional(self) -> bool
Is the field optional / nullable?
sourcepub fn is_updated_at(self) -> bool
pub fn is_updated_at(self) -> bool
Is there an @updatedAt
attribute on the field?
sourcepub fn field_type_as_enum(self) -> Option<EnumWalker<'db>>
pub fn field_type_as_enum(self) -> Option<EnumWalker<'db>>
Is this field’s type an enum? If yes, walk the enum.
sourcepub fn mapped_name(self) -> Option<&'db str>
pub fn mapped_name(self) -> Option<&'db str>
The name in the @map(<name>)
attribute.
sourcepub fn model(self) -> ModelWalker<'db>
pub fn model(self) -> ModelWalker<'db>
The model that contains the field.
sourcepub fn raw_native_type(
self
) -> Option<(&'db str, &'db str, &'db [String], Span)>
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”, &[],
sourcepub fn is_unsupported(self) -> bool
pub fn is_unsupported(self) -> bool
Is the type of the field Unsupported("...")
?
sourcepub fn default_value(self) -> Option<DefaultValueWalker<'db>>
pub fn default_value(self) -> Option<DefaultValueWalker<'db>>
The @default()
attribute of the field, if any.
sourcepub fn scalar_field_type(self) -> ScalarFieldType
pub fn scalar_field_type(self) -> ScalarFieldType
The type of the field.
sourcepub fn scalar_type(self) -> Option<ScalarType>
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).