toasty_sql/stmt/
add_column.rs

1use super::{ColumnDef, Statement};
2
3use toasty_core::{
4    driver::Capability,
5    schema::db::{Column, TableId},
6};
7
8/// A statement to add a column to a table.
9#[derive(Debug, Clone)]
10pub struct AddColumn {
11    /// ID of the table to add the column to.
12    pub table: TableId,
13
14    /// Column definition.
15    pub column: ColumnDef,
16}
17
18impl Statement {
19    /// Adds a column to a table.
20    pub fn add_column(column: &Column, capability: &Capability) -> Self {
21        AddColumn {
22            table: column.id.table,
23            column: ColumnDef::from_schema(column, &capability.storage_types),
24        }
25        .into()
26    }
27}
28
29impl From<AddColumn> for Statement {
30    fn from(value: AddColumn) -> Self {
31        Self::AddColumn(value)
32    }
33}