pub enum MySQLType {
Show 40 variants
Tinyint,
TinyintUnsigned,
Smallint,
SmallintUnsigned,
Mediumint,
MediumintUnsigned,
Int,
IntUnsigned,
Bigint,
BigintUnsigned,
Decimal,
DecimalUnsigned,
Float,
FloatUnsigned,
Double,
DoubleUnsigned,
Real,
RealUnsigned,
Boolean,
Bit,
Char,
Varchar,
Tinytext,
Text,
Mediumtext,
Longtext,
Binary,
Varbinary,
Tinyblob,
Blob,
Mediumblob,
Longblob,
Json,
Date,
Time,
Datetime,
Timestamp,
Year,
Enum(Vec<Cow<'static, str>>),
Set(Vec<Cow<'static, str>>),
}Expand description
A MySQL column type declaration.
This models MySQL 8.0.31’s common native scalar, character, binary, JSON,
temporal, and inline collection types. ENUM and SET values are kept as
data because they are part of the column declaration, not named schema
objects as they are in PostgreSQL.
Self::sql returns a type keyword. DDL renderers must append
Self::inline_values for ENUM and SET, because correct literal
escaping belongs to the DDL renderer’s SQL-mode policy.
Variants§
Tinyint
TINYINT, a signed 1-byte integer.
TinyintUnsigned
TINYINT UNSIGNED, an unsigned 1-byte integer.
Smallint
SMALLINT, a signed 2-byte integer.
SmallintUnsigned
SMALLINT UNSIGNED, an unsigned 2-byte integer.
Mediumint
MEDIUMINT, a signed 3-byte integer.
MediumintUnsigned
MEDIUMINT UNSIGNED, an unsigned 3-byte integer.
Int
INT, a signed 4-byte integer.
IntUnsigned
INT UNSIGNED, an unsigned 4-byte integer.
Bigint
BIGINT, a signed 8-byte integer.
BigintUnsigned
BIGINT UNSIGNED, an unsigned 8-byte integer.
Decimal
DECIMAL, an exact fixed-point number.
DecimalUnsigned
DECIMAL UNSIGNED, a non-negative exact fixed-point number.
Float
FLOAT, a single-precision approximate number.
FloatUnsigned
FLOAT UNSIGNED, a non-negative single-precision approximate number.
Double
DOUBLE, a double-precision approximate number.
DoubleUnsigned
DOUBLE UNSIGNED, a non-negative double-precision approximate number.
Real
REAL, MySQL’s SQL-mode-sensitive approximate number spelling.
RealUnsigned
REAL UNSIGNED, the non-negative form of MySQL’s REAL spelling.
Boolean
BOOLEAN, an alias for TINYINT(1) in MySQL.
Bit
BIT, a bit-value type.
Char
CHAR, a fixed-length character string.
Varchar
VARCHAR, a variable-length character string.
Tinytext
TINYTEXT.
Text
TEXT.
Mediumtext
MEDIUMTEXT.
Longtext
LONGTEXT.
Binary
BINARY, a fixed-length binary string.
Varbinary
VARBINARY, a variable-length binary string.
Tinyblob
TINYBLOB.
Blob
BLOB.
Mediumblob
MEDIUMBLOB.
Longblob
LONGBLOB.
Json
MySQL’s native binary JSON type.
Date
DATE.
Time
TIME.
Datetime
DATETIME, which does not apply time-zone conversion.
Timestamp
TIMESTAMP, which MySQL converts through the session time zone.
Year
YEAR.
Enum(Vec<Cow<'static, str>>)
A MySQL inline ENUM declaration and its ordered allowed values.
Set(Vec<Cow<'static, str>>)
A MySQL inline SET declaration and its allowed values.
Implementations§
Source§impl MySQLType
impl MySQLType
Sourcepub const fn parse_attribute(name: &str) -> Option<Self>
pub const fn parse_attribute(name: &str) -> Option<Self>
Parse a macro attribute name as a non-parameterized MySQL type.
ENUM and SET require inline values, so construct them with
Self::enum_values or Self::set_values instead.
Sourcepub fn enum_values<I, S>(values: I) -> Self
pub fn enum_values<I, S>(values: I) -> Self
Build a MySQL inline ENUM declaration from its allowed values.
Sourcepub fn set_values<I, S>(values: I) -> Self
pub fn set_values<I, S>(values: I) -> Self
Build a MySQL inline SET declaration from its allowed values.
Sourcepub fn inline_values(&self) -> Option<&[Cow<'static, str>]>
pub fn inline_values(&self) -> Option<&[Cow<'static, str>]>
Return the inline values for an ENUM or SET declaration.
Sourcepub const fn sql(&self) -> &'static str
pub const fn sql(&self) -> &'static str
Return this declaration’s SQL type keyword.
For ENUM and SET, use Self::inline_values to render their
declaration values in a DDL renderer.
Sourcepub const fn is_unsigned(&self) -> bool
pub const fn is_unsigned(&self) -> bool
Return whether this declaration carries MySQL’s UNSIGNED modifier.
Sourcepub const fn supports_auto_increment(&self) -> bool
pub const fn supports_auto_increment(&self) -> bool
Return whether this is an integer declaration eligible for
AUTO_INCREMENT.
Sourcepub const fn supports_generated_columns(&self) -> bool
pub const fn supports_generated_columns(&self) -> bool
Return whether this declaration can be the declared type of a MySQL generated column.
MySQL’s generated-column restrictions concern the expression and its other column attributes rather than one of these native type families.
Sourcepub fn is_valid_flag(&self, flag: &str) -> bool
pub fn is_valid_flag(&self, flag: &str) -> bool
Return whether a column attribute is compatible with this type alone.
Constraints involving multiple attributes, such as the prohibition on
an AUTO_INCREMENT generated column, belong to a column DDL model.