Struct datamodel_renderer::datamodel::Field
source · pub struct Field<'a> { /* private fields */ }
Expand description
A field in a model block.
Implementations§
source§impl<'a> Field<'a>
impl<'a> Field<'a>
sourcepub fn new(
name: impl Into<Cow<'a, str>>,
type_name: impl Into<Cow<'a, str>>
) -> Self
pub fn new( name: impl Into<Cow<'a, str>>, type_name: impl Into<Cow<'a, str>> ) -> Self
Create a new required model field declaration.
ⓘ
model User {
name String
// ^^^^^^ type_name
//^^^^ name
}
sourcepub fn optional(&mut self)
pub fn optional(&mut self)
Sets the field as optional.
ⓘ
model Address {
street String?
// ^ this
}
sourcepub fn array(&mut self)
pub fn array(&mut self)
Sets the field to be an array.
ⓘ
model Address {
street String[]
// ^^ this
}
sourcepub fn unsupported(&mut self)
pub fn unsupported(&mut self)
Sets the field to be unsupported.
ⓘ
model Address {
street Unsupported("foo")
// ^^^^^^^^^^^^^^^^^^ this
}
sourcepub fn map(&mut self, value: impl Into<Cow<'a, str>>)
pub fn map(&mut self, value: impl Into<Cow<'a, str>>)
Sets the field map attribute.
ⓘ
model Address {
street String @map("Straße")
^^^^^^ value
}
sourcepub fn documentation(&mut self, documentation: impl Into<Cow<'a, str>>)
pub fn documentation(&mut self, documentation: impl Into<Cow<'a, str>>)
Documentation of the field.
ⓘ
model Foo {
/// This is the documentation.
bar Int
}
sourcepub fn default(&mut self, value: DefaultValue<'a>)
pub fn default(&mut self, value: DefaultValue<'a>)
Sets the field default attribute.
ⓘ
model Address {
street String @default("Prenzlauer Allee")
^^^^^^^^^^^^^^^^ value
}
sourcepub fn native_type(
&mut self,
prefix: impl Into<Cow<'a, str>>,
type: impl Into<Cow<'a, str>>,
params: Vec<String>
)
pub fn native_type( &mut self, prefix: impl Into<Cow<'a, str>>, type: impl Into<Cow<'a, str>>, params: Vec<String> )
Sets the native type of the field.
ⓘ
model Address {
street String @db.VarChar(255)
// ^^^ param
// ^^^^^^^ type_name
// ^^ prefix
}
TODO: params
as &[&str]
when we get rid of the DML.
sourcepub fn updated_at(&mut self)
pub fn updated_at(&mut self)
Marks the field to hold the update timestamp.
ⓘ
model Address {
street String @updatedAt
// ^^^^^^^^^^ adds this
}
sourcepub fn unique(&mut self, options: UniqueFieldAttribute<'a>)
pub fn unique(&mut self, options: UniqueFieldAttribute<'a>)
Marks the field to hold a unique constraint.
ⓘ
model Address {
street String @unique(sort: Asc, length: 11)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this
}
sourcepub fn id(&mut self, definition: IdFieldDefinition<'a>)
pub fn id(&mut self, definition: IdFieldDefinition<'a>)
Marks the field to be the id of the model.
ⓘ
model Address {
street String @id
// ^^^ this
}
sourcepub fn relation(&mut self, relation: Relation<'a>)
pub fn relation(&mut self, relation: Relation<'a>)
Set the field to be a relation.
ⓘ
model Address {
street Street @relation(...)
// ^^^^^^^^^^^^^^ this
}
sourcepub fn ignore(&mut self)
pub fn ignore(&mut self)
Ignores the field.
ⓘ
model Address {
street Street @ignore
// ^^^^^^^ this
}
sourcepub fn commented_out(&mut self)
pub fn commented_out(&mut self)
Comments the field out.
Trait Implementations§
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Field<'a>
impl<'a> Send for Field<'a>
impl<'a> Sync for Field<'a>
impl<'a> Unpin for Field<'a>
impl<'a> UnwindSafe for Field<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more