pub trait DatabaseField: FromDbValue + ToDbFieldValue {
const TYPE: ColumnType;
const NULLABLE: bool = false;
}db only.Expand description
A trait denoting that some type can be used as a field in a database.
Required Associated Constants§
Sourceconst TYPE: ColumnType
const TYPE: ColumnType
The type of the column in the database as one of the variants of
the ColumnType enum.
§Changing the column type after initial implementation
Note that this should never be changed after the type is implemented. The migration generator is unable to detect a change in the column type and will not generate a migration for it. If the column type needs to be changed, a manual migration should be written, or a new type should be created.
This is especially important for types that are stored as fixed-length
strings in the database, as the migration generator cannot detect a
change in the string length. For this reason, it’s recommended to use
the LimitedString type for fixed-length strings (which uses const
generics, so each change in the length will be a new type) instead of
a custom type with a fixed length.
Provided Associated Constants§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl DatabaseField for bool
impl DatabaseField for bool
const TYPE: ColumnType = ColumnType::Boolean
Source§impl DatabaseField for f32
impl DatabaseField for f32
const TYPE: ColumnType = ColumnType::Float
Source§impl DatabaseField for f64
impl DatabaseField for f64
const TYPE: ColumnType = ColumnType::Double
Source§impl DatabaseField for i8
impl DatabaseField for i8
const TYPE: ColumnType = ColumnType::TinyInteger
Source§impl DatabaseField for i16
impl DatabaseField for i16
const TYPE: ColumnType = ColumnType::SmallInteger
Source§impl DatabaseField for i32
impl DatabaseField for i32
const TYPE: ColumnType = ColumnType::Integer
Source§impl DatabaseField for i64
impl DatabaseField for i64
const TYPE: ColumnType = ColumnType::BigInteger
Source§impl DatabaseField for u8
impl DatabaseField for u8
const TYPE: ColumnType = ColumnType::TinyUnsignedInteger
Source§impl DatabaseField for u16
impl DatabaseField for u16
const TYPE: ColumnType = ColumnType::SmallUnsignedInteger
Source§impl DatabaseField for u32
impl DatabaseField for u32
const TYPE: ColumnType = ColumnType::UnsignedInteger
Source§impl DatabaseField for u64
impl DatabaseField for u64
const TYPE: ColumnType = ColumnType::BigUnsignedInteger
Source§impl DatabaseField for String
impl DatabaseField for String
const TYPE: ColumnType = ColumnType::Text
Source§impl DatabaseField for Vec<u8>
impl DatabaseField for Vec<u8>
const TYPE: ColumnType = ColumnType::Blob
Source§impl DatabaseField for DateTime<FixedOffset>
impl DatabaseField for DateTime<FixedOffset>
const TYPE: ColumnType = ColumnType::DateTimeWithTimeZone
Source§impl DatabaseField for NaiveDate
impl DatabaseField for NaiveDate
const TYPE: ColumnType = ColumnType::Date
Source§impl DatabaseField for NaiveDateTime
impl DatabaseField for NaiveDateTime
const TYPE: ColumnType = ColumnType::DateTime
Source§impl DatabaseField for NaiveTime
impl DatabaseField for NaiveTime
const TYPE: ColumnType = ColumnType::Time
Source§impl DatabaseField for WeekdaySet
impl DatabaseField for WeekdaySet
const TYPE: ColumnType = ColumnType::TinyUnsignedInteger
Source§impl<T: DatabaseField> DatabaseField for Option<T>
impl<T: DatabaseField> DatabaseField for Option<T>
Implementors§
Source§impl DatabaseField for PasswordHash
impl DatabaseField for PasswordHash
const TYPE: ColumnType
Source§impl DatabaseField for Email
Defines the database field type for Email.
impl DatabaseField for Email
Defines the database field type for Email.
Emails are stored as strings with a maximum length of 254 characters, as specified in RFC 5321.