toasty_sql/stmt/
alter_table.rs

1use super::{Name, Statement};
2
3use toasty_core::schema::db::Table;
4
5/// A statement to alter a SQL table.
6#[derive(Debug, Clone)]
7pub struct AlterTable {
8    /// Current name of the table.
9    pub name: Name,
10
11    /// The alteration to apply.
12    pub action: AlterTableAction,
13}
14
15/// The action to perform in an ALTER TABLE statement.
16#[derive(Debug, Clone)]
17pub enum AlterTableAction {
18    /// Rename the table to a new name.
19    RenameTo(Name),
20}
21
22impl Statement {
23    /// Renames a table.
24    pub fn alter_table_rename_to(table: &Table, new_name: &str) -> Self {
25        AlterTable {
26            name: Name::from(&table.name[..]),
27            action: AlterTableAction::RenameTo(Name::from(new_name)),
28        }
29        .into()
30    }
31}
32
33impl From<AlterTable> for Statement {
34    fn from(value: AlterTable) -> Self {
35        Self::AlterTable(value)
36    }
37}