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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//! A backend module which provides a few generic traits
//! to implement SQL generation for different databases.
//! 
//! It also re-exports the generators for existing databases
//! so they can be used more conveniently.

#[cfg(feature = "pg")]
mod pg;
#[cfg(feature = "pg")]
pub use self::pg::Pg;

#[cfg(feature = "sqlite3")]
mod sqlite3;
#[cfg(feature = "sqlite3")]
pub use self::sqlite3::Sqlite;

#[allow(unused_imports)]
use {Type, Column};

/// A generic SQL generator trait
pub trait SqlGenerator {
    
    /// Create a new table with a name
    fn create_table(name: &str) -> String;

    /// Create a new table with a name, only if it doesn't exist
    fn create_table_if_not_exists(name: &str) -> String;

    /// Drop a table with a name 
    fn drop_table(name: &str) -> String;

    /// Drop a table with a name, only if it exists
    fn drop_table_if_exists(name: &str) -> String;

    /// Rename a table from <old> to <new>
    fn rename_table(old: &str, new: &str) -> String;

    /// Modify a table in some other way
    fn alter_table(name: &str) -> String;


    /// Create a new column with a type
    fn add_column(ex: bool, name: &str, column: &Column) -> String;

    /// Drop an existing column from the table
    fn drop_column(name: &str) -> String;

    /// Rename an existing column
    fn rename_column(old: &str, new: &str) -> String;
}