@@ -29,14 +29,13 @@ impl AlterTable {
29
29
/// ADD COLUMN age int not null
30
30
/// ```
31
31
///
32
- ///
33
- /// Available on crate feature `postgresql` only.
32
+ /// ### Available on crate feature `postgresql` and `mysql` only.
34
33
/// Multiples call of this method will build the SQL respecting the order of the calls
35
34
///
36
35
/// ### Example
37
36
///
38
37
/// ```
39
- /// # #[cfg(any(feature = "postgresql"))]
38
+ /// # #[cfg(any(feature = "postgresql", feature = "mysql" ))]
40
39
/// # {
41
40
/// # use sql_query_builder as sql;
42
41
/// let query = sql::AlterTable::new()
@@ -161,13 +160,13 @@ impl AlterTable {
161
160
/// DROP column login
162
161
/// ```
163
162
///
164
- /// Available on crate feature `postgresql` only.
163
+ /// ### Available on crate feature `postgresql` and `mysql ` only.
165
164
/// Multiples call of this method will build the SQL respecting the order of the calls
166
165
///
167
166
/// ### Example
168
167
///
169
168
/// ```
170
- /// # #[cfg(any(feature = "postgresql"))]
169
+ /// # #[cfg(any(feature = "postgresql", feature = "mysql" ))]
171
170
/// # {
172
171
/// # use sql_query_builder as sql;
173
172
/// let query = sql::AlterTable::new()
@@ -284,16 +283,17 @@ impl AlterTable {
284
283
}
285
284
}
286
285
287
- #[ cfg( any( doc, feature = "postgresql" , feature = "sqlite" ) ) ]
286
+ #[ cfg( any( doc, feature = "postgresql" , feature = "sqlite" , feature = "mysql" ) ) ]
288
287
#[ cfg_attr( docsrs, doc( cfg( feature = "postgresql" ) ) ) ]
289
288
#[ cfg_attr( docsrs, doc( cfg( feature = "sqlite" ) ) ) ]
289
+ #[ cfg_attr( docsrs, doc( cfg( feature = "mysql" ) ) ) ]
290
290
impl AlterTable {
291
291
/// Changes the column name or table constraints, this method overrides the previous value
292
292
///
293
293
/// ### Example
294
294
///
295
295
///```
296
- /// # #[cfg(any(feature = "postgresql", feature = "sqlite"))]
296
+ /// # #[cfg(any(feature = "postgresql", feature = "sqlite", feature = "mysql" ))]
297
297
/// # {
298
298
/// # use sql_query_builder as sql;
299
299
/// let query = sql::AlterTable::new()
@@ -311,11 +311,54 @@ impl AlterTable {
311
311
/// ```sql
312
312
/// ALTER TABLE users RENAME COLUMN address TO city
313
313
/// ```
314
+ ///
315
+ /// ### Available on crate feature `mysql` only.
316
+ /// Changes the table name, column name or table constraints,
317
+ /// multiples call of this method will build the SQL respecting the order of the calls
318
+ ///
319
+ /// ### Example
320
+ ///
321
+ ///```
322
+ /// # #[cfg(feature = "mysql")]
323
+ /// # {
324
+ /// # use sql_query_builder as sql;
325
+ /// let query = sql::AlterTable::new()
326
+ /// .alter_table("users")
327
+ /// .rename("TO users_old")
328
+ /// .rename("COLUMN name TO full_name")
329
+ /// .to_string();
330
+ ///
331
+ /// # let expected = "ALTER TABLE users RENAME TO users_old, RENAME COLUMN name TO full_name";
332
+ /// # assert_eq!(expected, query);
333
+ /// # }
334
+ /// ```
335
+ ///
336
+ /// Outputs
337
+ ///
338
+ /// ```sql
339
+ /// ALTER TABLE users
340
+ /// RENAME TO users_old,
341
+ /// RENAME COLUMN name TO full_name
342
+ /// ```
314
343
pub fn rename ( mut self , action : & str ) -> Self {
315
- self . _rename = action. trim ( ) . to_string ( ) ;
344
+ #[ cfg( feature = "mysql" ) ]
345
+ {
346
+ let action = AlterTableActionItem ( AlterTableOrderedAction :: Rename , action. trim ( ) . to_string ( ) ) ;
347
+ push_unique ( & mut self . _ordered_actions , action) ;
348
+ }
349
+ #[ cfg( not( feature = "mysql" ) ) ]
350
+ {
351
+ self . _rename = action. trim ( ) . to_string ( ) ;
352
+ }
353
+
316
354
self
317
355
}
356
+ }
318
357
358
+ #[ cfg( any( doc, feature = "postgresql" , feature = "sqlite" ) ) ]
359
+ #[ cfg_attr( docsrs, doc( cfg( feature = "postgresql" ) ) ) ]
360
+ #[ cfg_attr( docsrs, doc( cfg( feature = "sqlite" ) ) ) ]
361
+ impl AlterTable {
319
362
/// Changes the name of the table, this method overrides the previous value
320
363
///
321
364
/// ### Example
@@ -345,16 +388,17 @@ impl AlterTable {
345
388
}
346
389
}
347
390
348
- #[ cfg( any( doc, feature = "postgresql" ) ) ]
391
+ #[ cfg( any( doc, feature = "postgresql" , feature = "mysql" ) ) ]
349
392
#[ cfg_attr( docsrs, doc( cfg( feature = "postgresql" ) ) ) ]
393
+ #[ cfg_attr( docsrs, doc( cfg( feature = "mysql" ) ) ) ]
350
394
impl AlterTable {
351
395
/// Alter columns or table constraints.
352
396
/// Multiples call of this method will build the SQL respecting the order of the calls
353
397
///
354
398
/// ### Example
355
399
///
356
400
///```
357
- /// # #[cfg(any(feature = "postgresql"))]
401
+ /// # #[cfg(any(feature = "postgresql", feature = "mysql" ))]
358
402
/// # {
359
403
/// # use sql_query_builder as sql;
360
404
/// let query = sql::AlterTable::new()
0 commit comments