pub struct Field<'a> { /* private fields */ }
Expand description

A field in a model block.

Implementations§

source§

impl<'a> Field<'a>

source

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
}
source

pub fn optional(&mut self)

Sets the field as optional.

model Address {
  street String?
//             ^ this
}
source

pub fn array(&mut self)

Sets the field to be an array.

model Address {
  street String[]
//             ^^ this
}
source

pub fn unsupported(&mut self)

Sets the field to be unsupported.

model Address {
  street Unsupported("foo")
//       ^^^^^^^^^^^^^^^^^^ this
}
source

pub fn map(&mut self, value: impl Into<Cow<'a, str>>)

Sets the field map attribute.

model Address {
  street String @map("Straße")
                      ^^^^^^ value
}
source

pub fn documentation(&mut self, documentation: impl Into<Cow<'a, str>>)

Documentation of the field.

model Foo {
  /// This is the documentation.
  bar Int
}
source

pub fn default(&mut self, value: DefaultValue<'a>)

Sets the field default attribute.

model Address {
  street String @default("Prenzlauer Allee")
                          ^^^^^^^^^^^^^^^^ value
}
source

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.

source

pub fn updated_at(&mut self)

Marks the field to hold the update timestamp.

model Address {
  street String @updatedAt
//              ^^^^^^^^^^ adds this
}
source

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
}
source

pub fn id(&mut self, definition: IdFieldDefinition<'a>)

Marks the field to be the id of the model.

model Address {
  street String @id
//              ^^^ this
}
source

pub fn relation(&mut self, relation: Relation<'a>)

Set the field to be a relation.

model Address {
  street Street @relation(...)
//              ^^^^^^^^^^^^^^ this
}
source

pub fn ignore(&mut self)

Ignores the field.

model Address {
  street Street @ignore
//              ^^^^^^^ this
}
source

pub fn commented_out(&mut self)

Comments the field out.

Trait Implementations§

source§

impl<'a> Debug for Field<'a>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a> Display for Field<'a>

source§

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

Formats the value using the given formatter. Read more

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> 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.