1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::{Dialect, Table, Column, ToSql};
use crate::util::SqlExtension;

/// Create table action
#[derive(Debug)]
pub struct CreateTable {
    pub schema: Option<String>,
    pub name: String,
    pub columns: Vec<Column>,
}


impl CreateTable {
    pub fn from_table(table: &Table) -> CreateTable {
        CreateTable {
            schema: table.schema.clone(),
            name: table.name.clone(),
            columns: table.columns.clone(),
        }
    }
}

impl ToSql for CreateTable {
    fn write_sql(&self, buf: &mut String, dialect: Dialect) {
        buf.push_str("CREATE TABLE ");
        buf.push_table_name(&self.schema, &self.name);
        buf.push_str(" (\n");
        buf.push_sql_sequence(&self.columns, ",\n", dialect);
        buf.push_str("\n)");
    }
}