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>
Parses a type name from a column attribute, ignoring case. Returns
None for an unknown name.
Unsigned types use an _unsigned suffix ("int_unsigned"), and
common aliases are accepted ("integer", "numeric", "bool",
"character_varying", …). ENUM and SET need their values, so
build them with Self::enum_values or Self::set_values instead.
§Examples
use drizzle_types::mysql::MySQLType;
assert_eq!(MySQLType::parse_attribute("int_unsigned"), Some(MySQLType::IntUnsigned));
assert_eq!(MySQLType::parse_attribute("Integer"), Some(MySQLType::Int));
assert_eq!(MySQLType::parse_attribute("enum"), None);Sourcepub fn enum_values<I, S>(values: I) -> Self
pub fn enum_values<I, S>(values: I) -> Self
Creates an inline ENUM type from its allowed values, in order.
Sourcepub fn set_values<I, S>(values: I) -> Self
pub fn set_values<I, S>(values: I) -> Self
Creates an inline SET type from its allowed values.
Sourcepub fn inline_values(&self) -> Option<&[Cow<'static, str>]>
pub fn inline_values(&self) -> Option<&[Cow<'static, str>]>
Returns the values of an ENUM or SET type, or None for any other
type.
Sourcepub const fn sql(&self) -> &'static str
pub const fn sql(&self) -> &'static str
Returns the SQL type keyword, such as "INT UNSIGNED", without any
arguments.
ENUM and SET return just "ENUM" / "SET"; their values come
from Self::inline_values.
§Examples
use drizzle_types::mysql::MySQLType;
assert_eq!(MySQLType::BigintUnsigned.sql(), "BIGINT UNSIGNED");
assert_eq!(MySQLType::enum_values(["a", "b"]).sql(), "ENUM");Sourcepub const fn is_unsigned(&self) -> bool
pub const fn is_unsigned(&self) -> bool
Returns true for the ... UNSIGNED variants.
Sourcepub const fn supports_auto_increment(&self) -> bool
pub const fn supports_auto_increment(&self) -> bool
Returns true for the integer types, which can be AUTO_INCREMENT.
Sourcepub const fn supports_generated_columns(&self) -> bool
pub const fn supports_generated_columns(&self) -> bool
Returns whether a column of this type can be a generated column.
Always true: MySQL restricts the expression, not the column type.
Sourcepub fn is_valid_flag(&self, flag: &str) -> bool
pub fn is_valid_flag(&self, flag: &str) -> bool
Returns whether the column attribute flag (such as "unique" or
"auto_increment") is allowed on a column of this type. Unknown flags
return false.
This checks the type alone. Rules that involve two attributes, such
as no AUTO_INCREMENT on a generated column, are checked elsewhere.