lua_sql_builder/mysql/
create.rs

1pub struct Create<'a> {
2    columns: &'a str,
3    table: &'a str,
4}
5
6#[allow(dead_code)]
7impl<'a> Create<'a> {
8    pub fn new(table: &'a str) -> Create<'a> {
9        Create { table, columns: "" }
10    }
11
12    pub fn columns(&mut self, columns: &'a str) -> &Create<'a> {
13        self.columns = columns;
14        self
15    }
16
17    pub fn build(&self) -> String {
18        let mut statement = "CREATE TABLE IF NOT EXISTS ".to_string();
19        statement.push_str(&format!("{}", self.table));
20        if self.columns.len() > 0 {
21            statement.push_str(&format!(" ({})", self.columns));
22        }
23
24        statement = statement.trim().to_string() + ";";
25        statement
26    }
27}