Skip to main content

MySQLType

Enum MySQLType 

Source
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

Source

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.

Source

pub fn enum_values<I, S>(values: I) -> Self
where I: IntoIterator<Item = S>, S: Into<Cow<'static, str>>,

Build a MySQL inline ENUM declaration from its allowed values.

Source

pub fn set_values<I, S>(values: I) -> Self
where I: IntoIterator<Item = S>, S: Into<Cow<'static, str>>,

Build a MySQL inline SET declaration from its allowed values.

Source

pub fn inline_values(&self) -> Option<&[Cow<'static, str>]>

Return the inline values for an ENUM or SET declaration.

Source

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.

Source

pub const fn is_unsigned(&self) -> bool

Return whether this declaration carries MySQL’s UNSIGNED modifier.

Source

pub const fn supports_auto_increment(&self) -> bool

Return whether this is an integer declaration eligible for AUTO_INCREMENT.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for MySQLType

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MySQLType

Source§

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

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

impl Default for MySQLType

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for MySQLType

Source§

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

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

impl Eq for MySQLType

Source§

impl Hash for MySQLType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MySQLType

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MySQLType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.