Skip to content

Commit 010db5d

Browse files
committed
Removed mysql
1 parent e2c4ab2 commit 010db5d

15 files changed

Lines changed: 7 additions & 668 deletions

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ all-features = true
4141
sqlite = [
4242
"dep:libsqlite3-sys",
4343
]
44-
mysql = []
4544
postgres = []
4645
postgres-only = [
4746
"postgres",

src/alter_table.rs

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ pub enum AlterTableImpl<'until_build, 'post_build> {
6969
#[cfg(feature = "sqlite")]
7070
SQLite(AlterTableData<'until_build, 'post_build>),
7171
/**
72-
MySQL representation of the ALTER TABLE operation.
73-
*/
74-
#[cfg(feature = "mysql")]
75-
MySQL(AlterTableData<'until_build, 'post_build>),
76-
/**
7772
Postgres representation of the ALTER TABLE operation.
7873
*/
7974
#[cfg(feature = "postgres")]
@@ -102,14 +97,7 @@ impl<'post_build> AlterTable<'post_build> for AlterTableImpl<'_, 'post_build> {
10297
AlterTableOperation::AddColumn { mut operation } => {
10398
write!(s, "ADD COLUMN ").unwrap();
10499

105-
#[cfg(any(feature = "mysql", feature = "postgres"))]
106-
if let CreateColumnImpl::SQLite(ref mut ccd) = operation {
107-
ccd.statements = Some(&mut d.statements);
108-
ccd.lookup = Some(&mut d.lookup);
109-
}
110-
#[cfg(not(any(feature = "mysql", feature = "postgres")))]
111-
{
112-
let CreateColumnImpl::SQLite(ref mut ccd) = operation;
100+
if let CreateColumnImpl::SQLite(ccd) = &mut operation {
113101
ccd.statements = Some(&mut d.statements);
114102
ccd.lookup = Some(&mut d.lookup);
115103
}
@@ -128,47 +116,6 @@ impl<'post_build> AlterTable<'post_build> for AlterTableImpl<'_, 'post_build> {
128116

129117
Ok(statements)
130118
}
131-
#[cfg(feature = "mysql")]
132-
AlterTableImpl::MySQL(mut d) => {
133-
let mut s = format!("ALTER TABLE `{}` ", d.name);
134-
135-
match d.operation {
136-
AlterTableOperation::RenameTo { name } => {
137-
write!(s, "RENAME TO `{name}`").unwrap();
138-
}
139-
AlterTableOperation::RenameColumnTo {
140-
column_name,
141-
new_column_name,
142-
} => write!(s, "RENAME COLUMN `{column_name}` TO `{new_column_name}`").unwrap(),
143-
AlterTableOperation::AddColumn { mut operation } => {
144-
write!(s, "ADD COLUMN ").unwrap();
145-
146-
#[cfg(any(feature = "sqlite", feature = "postgres"))]
147-
if let CreateColumnImpl::MySQL(ref mut ccd) = operation {
148-
ccd.statements = Some(&mut d.statements);
149-
ccd.lookup = Some(&mut d.lookup);
150-
}
151-
#[cfg(not(any(feature = "sqlite", feature = "postgres")))]
152-
{
153-
let CreateColumnImpl::MySQL(ref mut ccd) = operation;
154-
ccd.statements = Some(&mut d.statements);
155-
ccd.lookup = Some(&mut d.lookup);
156-
}
157-
158-
operation.build(&mut s)?;
159-
}
160-
AlterTableOperation::DropColumn { name } => {
161-
write!(s, "DROP COLUMN `{name}`").unwrap()
162-
}
163-
};
164-
165-
write!(s, ";").unwrap();
166-
167-
let mut statements = vec![(s, d.lookup)];
168-
statements.extend(d.statements);
169-
170-
Ok(statements)
171-
}
172119
#[cfg(feature = "postgres")]
173120
AlterTableImpl::Postgres(mut d) => {
174121
let mut s = format!("ALTER TABLE \"{}\" ", d.name);
@@ -191,13 +138,8 @@ impl<'post_build> AlterTable<'post_build> for AlterTableImpl<'_, 'post_build> {
191138
AlterTableOperation::AddColumn { mut operation } => {
192139
write!(s, "ADD COLUMN ").unwrap();
193140

194-
#[cfg(any(feature = "sqlite", feature = "mysql"))]
195-
if let CreateColumnImpl::Postgres(ref mut ccd) = operation {
196-
ccd.statements = Some(&mut d.statements);
197-
}
198-
#[cfg(not(any(feature = "sqlite", feature = "mysql")))]
199-
{
200-
let CreateColumnImpl::Postgres(ref mut ccd) = operation;
141+
#[allow(irrefutable_let_patterns)]
142+
if let CreateColumnImpl::Postgres(ccd) = &mut operation {
201143
ccd.statements = Some(&mut d.statements);
202144
}
203145

src/conditional.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
use std::fmt::{Debug, Error, Write};
22

3-
#[cfg(feature = "mysql")]
4-
use crate::db_specific::mysql;
53
#[cfg(feature = "postgres")]
64
use crate::db_specific::postgres;
75
#[cfg(feature = "sqlite")]
@@ -274,13 +272,6 @@ impl<'a> BuildCondition<'a> for Condition<'a> {
274272
}
275273
write!(writer, "{column_name}")
276274
}
277-
#[cfg(feature = "mysql")]
278-
DBImpl::MySQL => {
279-
if let Some(table_name) = table_name {
280-
write!(writer, "{table_name}.")?;
281-
}
282-
write!(writer, "{column_name}")
283-
}
284275
#[cfg(feature = "postgres")]
285276
DBImpl::Postgres => {
286277
if let Some(table_name) = table_name {
@@ -292,8 +283,6 @@ impl<'a> BuildCondition<'a> for Condition<'a> {
292283
Value::Choice(c) => match dialect {
293284
#[cfg(feature = "sqlite")]
294285
DBImpl::SQLite => write!(writer, "{}", sqlite::fmt(c)),
295-
#[cfg(feature = "mysql")]
296-
DBImpl::MySQL => write!(writer, "{}", mysql::fmt(c)),
297286
#[cfg(feature = "postgres")]
298287
DBImpl::Postgres => write!(writer, "{}", postgres::fmt(c)),
299288
},
@@ -306,10 +295,6 @@ impl<'a> BuildCondition<'a> for Condition<'a> {
306295
DBImpl::SQLite => {
307296
write!(writer, "?")
308297
}
309-
#[cfg(feature = "mysql")]
310-
DBImpl::MySQL => {
311-
write!(writer, "?")
312-
}
313298
#[cfg(feature = "postgres")]
314299
DBImpl::Postgres => {
315300
write!(writer, "${}", lookup.len())

src/create_column.rs

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use rorm_declaration::imr::DefaultValue;
66
use crate::create_trigger::trigger_annotation_to_trigger_postgres;
77
#[cfg(feature = "sqlite")]
88
use crate::create_trigger::trigger_annotation_to_trigger_sqlite;
9-
#[cfg(feature = "mysql")]
10-
use crate::db_specific::mysql;
119
#[cfg(feature = "postgres")]
1210
use crate::db_specific::postgres;
1311
#[cfg(feature = "sqlite")]
@@ -50,19 +48,6 @@ pub struct CreateColumnSQLiteData<'until_build, 'post_build> {
5048
pub(crate) lookup: Option<&'until_build mut Vec<Value<'post_build>>>,
5149
}
5250

53-
/**
54-
Representation of the data of the creation of a column for the mysql dialect
55-
*/
56-
#[derive(Debug)]
57-
#[cfg(feature = "mysql")]
58-
pub struct CreateColumnMySQLData<'until_build, 'post_build> {
59-
pub(crate) name: &'until_build str,
60-
pub(crate) data_type: DbType,
61-
pub(crate) annotations: Vec<SQLAnnotation<'post_build>>,
62-
pub(crate) statements: Option<&'until_build mut Vec<(String, Vec<Value<'post_build>>)>>,
63-
pub(crate) lookup: Option<&'until_build mut Vec<Value<'post_build>>>,
64-
}
65-
6651
/**
6752
Representation of the data of the creation of a column for the mysql dialect
6853
*/
@@ -90,11 +75,6 @@ pub enum CreateColumnImpl<'until_build, 'post_build> {
9075
#[cfg(feature = "sqlite")]
9176
SQLite(CreateColumnSQLiteData<'until_build, 'post_build>),
9277
/**
93-
MySQL representation of the create column operation.
94-
*/
95-
#[cfg(feature = "mysql")]
96-
MySQL(CreateColumnMySQLData<'until_build, 'post_build>),
97-
/**
9878
Postgres representation of the create column operation.
9979
*/
10080
#[cfg(feature = "postgres")]
@@ -191,147 +171,6 @@ impl<'post_build> CreateColumn<'post_build> for CreateColumnImpl<'_, 'post_build
191171

192172
Ok(())
193173
}
194-
#[cfg(feature = "mysql")]
195-
CreateColumnImpl::MySQL(mut d) => {
196-
write!(s, "`{}` ", d.name).unwrap();
197-
198-
match d.data_type {
199-
DbType::VarChar => {
200-
let a_opt = d
201-
.annotations
202-
.iter()
203-
.find(|x| x.annotation.eq_shallow(&Annotation::MaxLength(0)));
204-
205-
if let Some(a) = a_opt {
206-
if let Annotation::MaxLength(max_length) = a.annotation {
207-
// utf8mb4 is 4 bytes wide, so that's the maximum for varchar
208-
if *max_length < 2i32.pow(14) - 1 {
209-
write!(s, "VARCHAR({max_length}) ").unwrap();
210-
} else {
211-
write!(s, "LONGTEXT ").unwrap();
212-
}
213-
} else {
214-
return Err(Error::SQLBuildError(String::from(
215-
"VARCHAR must have a max_length annotation",
216-
)));
217-
}
218-
} else {
219-
return Err(Error::SQLBuildError(String::from(
220-
"VARCHAR must have a max_length annotation",
221-
)));
222-
}
223-
}
224-
DbType::Binary | DbType::Uuid => write!(s, "LONGBLOB ").unwrap(),
225-
DbType::Int8 => write!(s, "TINYINT(255) ").unwrap(),
226-
DbType::Int16 => write!(s, "SMALLINT(255) ").unwrap(),
227-
DbType::Int32 => write!(s, "INT(255) ").unwrap(),
228-
DbType::Int64 => write!(s, "BIGINT(255) ").unwrap(),
229-
DbType::Float => write!(s, "FLOAT(24) ").unwrap(),
230-
DbType::Double => write!(s, "DOUBLE(53) ").unwrap(),
231-
DbType::Boolean => write!(s, "BOOL ").unwrap(),
232-
DbType::Date => write!(s, "DATE ").unwrap(),
233-
DbType::DateTime => write!(s, "DATETIME ").unwrap(),
234-
DbType::Timestamp => write!(s, "TIMESTAMP ").unwrap(),
235-
DbType::Time => write!(s, "TIME ").unwrap(),
236-
DbType::Choices => {
237-
let a_opt = d.annotations.iter().find(|x| {
238-
x.annotation
239-
.eq_shallow(&Annotation::Choices(Default::default()))
240-
});
241-
242-
if let Some(a) = a_opt {
243-
if let Annotation::Choices(values) = a.annotation {
244-
write!(
245-
s,
246-
"ENUM({}) ",
247-
values
248-
.iter()
249-
.map(|x| mysql::fmt(x))
250-
.collect::<Vec<String>>()
251-
.join(", ")
252-
)
253-
.unwrap();
254-
} else {
255-
return Err(Error::SQLBuildError(
256-
"VARCHAR must have a MaxLength annotation".to_string(),
257-
));
258-
}
259-
} else {
260-
return Err(Error::SQLBuildError(
261-
"VARCHAR must have a MaxLength annotation".to_string(),
262-
));
263-
}
264-
}
265-
DbType::BitVec | DbType::IpNetwork | DbType::MacAddress => {
266-
unreachable!("BitVec, MacAddress and IpNetwork are not available for mysql")
267-
}
268-
};
269-
270-
for (idx, x) in d.annotations.iter().enumerate() {
271-
match &x.annotation {
272-
Annotation::AutoIncrement => write!(s, "AUTO_INCREMENT").unwrap(),
273-
Annotation::AutoCreateTime => {
274-
write!(
275-
s,
276-
"DEFAULT {}",
277-
match d.data_type {
278-
DbType::Date => "CURRENT_DATE",
279-
DbType::DateTime => "CURRENT_TIMESTAMP",
280-
DbType::Timestamp => "CURRENT_TIMESTAMP",
281-
DbType::Time => "CURRENT_TIME",
282-
_ => "",
283-
}
284-
)
285-
.unwrap();
286-
}
287-
Annotation::AutoUpdateTime => write!(
288-
s,
289-
"ON UPDATE {}",
290-
match d.data_type {
291-
DbType::Date => "CURRENT_DATE",
292-
DbType::DateTime => "CURRENT_TIMESTAMP",
293-
DbType::Timestamp => "CURRENT_TIMESTAMP",
294-
DbType::Time => "CURRENT_TIME",
295-
_ => "",
296-
}
297-
)
298-
.unwrap(),
299-
Annotation::DefaultValue(v) => match v {
300-
DefaultValue::String(dv) => {
301-
if let Some(l) = &mut d.lookup {
302-
l.push(Value::String(dv))
303-
}
304-
write!(s, "DEFAULT ?").unwrap();
305-
}
306-
DefaultValue::Integer(i) => write!(s, "DEFAULT {i}").unwrap(),
307-
DefaultValue::Float(f) => write!(s, "DEFAULT {f}").unwrap(),
308-
DefaultValue::Boolean(b) => {
309-
if *b {
310-
write!(s, "DEFAULT 1").unwrap();
311-
} else {
312-
write!(s, "DEFAULT 0").unwrap();
313-
}
314-
}
315-
},
316-
Annotation::NotNull => write!(s, "NOT NULL").unwrap(),
317-
Annotation::PrimaryKey => write!(s, "PRIMARY KEY").unwrap(),
318-
Annotation::Unique => write!(s, "UNIQUE").unwrap(),
319-
Annotation::ForeignKey(fk) => write!(
320-
s,
321-
"REFERENCES `{}`(`{}`) ON DELETE {} ON UPDATE {}",
322-
fk.table_name, fk.column_name, fk.on_delete, fk.on_update
323-
)
324-
.unwrap(),
325-
_ => {}
326-
}
327-
328-
if idx != d.annotations.len() - 1 {
329-
write!(s, " ").unwrap();
330-
}
331-
}
332-
333-
Ok(())
334-
}
335174
#[cfg(feature = "postgres")]
336175
CreateColumnImpl::Postgres(mut d) => {
337176
write!(s, "\"{}\" ", d.name).unwrap();

0 commit comments

Comments
 (0)