#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MySQLIndexMethod {
BTree,
Hash,
}
impl MySQLIndexMethod {
#[must_use]
pub const fn as_sql(self) -> &'static str {
match self {
Self::BTree => "BTREE",
Self::Hash => "HASH",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MySQLIndexAlgorithm {
Default,
Inplace,
Copy,
}
impl MySQLIndexAlgorithm {
#[must_use]
pub const fn as_sql(self) -> &'static str {
match self {
Self::Default => "DEFAULT",
Self::Inplace => "INPLACE",
Self::Copy => "COPY",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MySQLIndexLock {
Default,
None,
Shared,
Exclusive,
}
impl MySQLIndexLock {
#[must_use]
pub const fn as_sql(self) -> &'static str {
match self {
Self::Default => "DEFAULT",
Self::None => "NONE",
Self::Shared => "SHARED",
Self::Exclusive => "EXCLUSIVE",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IndexOrder {
Asc,
Desc,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum IndexKeyPart {
Column {
name: &'static str,
length: Option<u32>,
order: Option<IndexOrder>,
},
Expression {
sql: &'static str,
order: Option<IndexOrder>,
},
}
#[doc(hidden)]
#[diagnostic::on_unimplemented(
message = "`{Self}` does not support a MySQL index prefix length",
note = "prefix lengths are supported for character, binary, TEXT, and BLOB columns"
)]
pub trait IndexPrefixType {}
#[doc(hidden)]
#[diagnostic::on_unimplemented(
message = "`{Self}` cannot be used directly in a MySQL index",
note = "TEXT and BLOB columns need a prefix length; JSON needs an indexed scalar expression"
)]
pub trait IndexType {}
macro_rules! impl_index_types {
($trait:ident: $($type:ty),+ $(,)?) => {
$(impl $trait for $type {})+
};
}
impl_index_types! { IndexPrefixType:
crate::types::Char,
crate::types::Varchar,
crate::types::TinyText,
crate::types::Text,
crate::types::MediumText,
crate::types::LongText,
crate::types::Binary,
crate::types::Varbinary,
crate::types::TinyBlob,
crate::types::Blob,
crate::types::MediumBlob,
crate::types::LongBlob,
}
impl_index_types! { IndexType:
crate::types::TinyInt,
crate::types::TinyIntUnsigned,
crate::types::SmallInt,
crate::types::SmallIntUnsigned,
crate::types::MediumInt,
crate::types::MediumIntUnsigned,
crate::types::Int,
crate::types::IntUnsigned,
crate::types::BigInt,
crate::types::BigIntUnsigned,
crate::types::Float,
crate::types::Double,
crate::types::Decimal,
crate::types::Boolean,
crate::types::Char,
crate::types::Varchar,
crate::types::Binary,
crate::types::Varbinary,
crate::types::Date,
crate::types::Time,
crate::types::DateTime,
crate::types::Timestamp,
crate::types::Year,
crate::types::Enum,
crate::types::Set,
crate::types::Bit,
}
pub trait MySQLIndexMetadata {
const KEY_PARTS: &'static [IndexKeyPart];
const METHOD: Option<MySQLIndexMethod>;
const ALGORITHM: Option<MySQLIndexAlgorithm>;
const LOCK: Option<MySQLIndexLock>;
}
#[doc(hidden)]
pub mod __private {
pub trait MySQLSchemaItemSealed {}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MySQLInlineTypeMetadata {
Enum(&'static [&'static str]),
Set(&'static [&'static str]),
}
pub trait MySQLSchemaItemMetadata: __private::MySQLSchemaItemSealed {
const INDEX_KEY_PARTS: &'static [IndexKeyPart] = &[];
const INDEX_METHOD: Option<MySQLIndexMethod> = None;
const INDEX_ALGORITHM: Option<MySQLIndexAlgorithm> = None;
const INDEX_LOCK: Option<MySQLIndexLock> = None;
fn inline_type(_column: &str) -> Option<MySQLInlineTypeMetadata> {
None
}
fn column_comment(_column: &str) -> Option<&'static str> {
None
}
}