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
pub struct Create<'a> {
    columns: &'a str,
    table: &'a str,
}

#[allow(dead_code)]
impl<'a> Create<'a> {
    pub fn new(table: &'a str) -> Create<'a> {
        Create { table, columns: "" }
    }

    pub fn columns(&mut self, columns: &'a str) -> &Create<'a> {
        self.columns = columns;
        self
    }

    pub fn build(&self) -> String {
        let mut statement = "CREATE TABLE IF NOT EXISTS ".to_string();
        statement.push_str(&format!("{}", self.table));
        if self.columns.len() > 0 {
            statement.push_str(&format!(" ({})", self.columns));
        }

        statement = statement.trim().to_string() + ";";
        statement
    }
}