1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
6pub enum MySQLIndexMethod {
7 BTree,
9 Hash,
11}
12
13impl MySQLIndexMethod {
14 #[must_use]
16 pub const fn as_sql(self) -> &'static str {
17 match self {
18 Self::BTree => "BTREE",
19 Self::Hash => "HASH",
20 }
21 }
22}
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
26pub enum MySQLIndexAlgorithm {
27 Default,
29 Inplace,
31 Copy,
33}
34
35impl MySQLIndexAlgorithm {
36 #[must_use]
38 pub const fn as_sql(self) -> &'static str {
39 match self {
40 Self::Default => "DEFAULT",
41 Self::Inplace => "INPLACE",
42 Self::Copy => "COPY",
43 }
44 }
45}
46
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
49pub enum MySQLIndexLock {
50 Default,
52 None,
54 Shared,
56 Exclusive,
58}
59
60impl MySQLIndexLock {
61 #[must_use]
63 pub const fn as_sql(self) -> &'static str {
64 match self {
65 Self::Default => "DEFAULT",
66 Self::None => "NONE",
67 Self::Shared => "SHARED",
68 Self::Exclusive => "EXCLUSIVE",
69 }
70 }
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
75pub enum IndexOrder {
76 Asc,
78 Desc,
80}
81
82#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
84pub enum IndexKeyPart {
85 Column {
87 name: &'static str,
89 length: Option<u32>,
91 order: Option<IndexOrder>,
93 },
94 Expression {
96 sql: &'static str,
98 order: Option<IndexOrder>,
100 },
101}
102
103#[doc(hidden)]
108#[diagnostic::on_unimplemented(
109 message = "`{Self}` does not support a MySQL index prefix length",
110 note = "prefix lengths are supported for character, binary, TEXT, and BLOB columns"
111)]
112pub trait IndexPrefixType {}
113
114#[doc(hidden)]
119#[diagnostic::on_unimplemented(
120 message = "`{Self}` cannot be used directly in a MySQL index",
121 note = "TEXT and BLOB columns need a prefix length; JSON needs an indexed scalar expression"
122)]
123pub trait IndexType {}
124
125macro_rules! impl_index_types {
126 ($trait:ident: $($type:ty),+ $(,)?) => {
127 $(impl $trait for $type {})+
128 };
129}
130
131impl_index_types! { IndexPrefixType:
132 crate::types::Char,
133 crate::types::Varchar,
134 crate::types::TinyText,
135 crate::types::Text,
136 crate::types::MediumText,
137 crate::types::LongText,
138 crate::types::Binary,
139 crate::types::Varbinary,
140 crate::types::TinyBlob,
141 crate::types::Blob,
142 crate::types::MediumBlob,
143 crate::types::LongBlob,
144}
145
146impl_index_types! { IndexType:
147 crate::types::TinyInt,
148 crate::types::TinyIntUnsigned,
149 crate::types::SmallInt,
150 crate::types::SmallIntUnsigned,
151 crate::types::MediumInt,
152 crate::types::MediumIntUnsigned,
153 crate::types::Int,
154 crate::types::IntUnsigned,
155 crate::types::BigInt,
156 crate::types::BigIntUnsigned,
157 crate::types::Float,
158 crate::types::Double,
159 crate::types::Decimal,
160 crate::types::Boolean,
161 crate::types::Char,
162 crate::types::Varchar,
163 crate::types::Binary,
164 crate::types::Varbinary,
165 crate::types::Date,
166 crate::types::Time,
167 crate::types::DateTime,
168 crate::types::Timestamp,
169 crate::types::Year,
170 crate::types::Enum,
171 crate::types::Set,
172 crate::types::Bit,
173}
174
175#[doc(hidden)]
181pub mod __private {
182 pub trait MySQLSchemaItemSealed {}
183}
184
185#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
191pub enum MySQLInlineTypeMetadata {
192 Enum(&'static [&'static str]),
194 Set(&'static [&'static str]),
196}
197
198pub trait MySQLSchemaItemMetadata: __private::MySQLSchemaItemSealed {
204 const INDEX_KEY_PARTS: &'static [IndexKeyPart] = &[];
206 const INDEX_METHOD: Option<MySQLIndexMethod> = None;
208 const INDEX_ALGORITHM: Option<MySQLIndexAlgorithm> = None;
210 const INDEX_LOCK: Option<MySQLIndexLock> = None;
212
213 fn inline_type(_column: &str) -> Option<MySQLInlineTypeMetadata> {
216 None
217 }
218
219 fn column_comment(_column: &str) -> Option<&'static str> {
224 None
225 }
226}