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
use crate::sql::{TypeWriter, FieldType};

/// PostgreSQL type serializator
#[derive(Debug)]
pub struct Postgresql {}
impl TypeWriter for Postgresql {
    fn type_to_sql(&self, field_type:&FieldType) -> String {
        match field_type {
            FieldType::Int => "int".to_owned(),
            FieldType::BigInt => "bigint".to_owned(),
            FieldType::Txt => "text".to_owned(),
            FieldType::Bool => "bool".to_owned(),
            FieldType::Dbl => "double precision".to_owned(),
            FieldType::AutoInc => "serial".to_owned(),
        }
    }
}

/// MySQL type serializator
#[derive(Debug)]
pub struct Mysql {}
impl TypeWriter for Mysql {
    fn type_to_sql(&self, field_type:&FieldType) -> String {
        match field_type {
            FieldType::Int => "int".to_owned(),
            FieldType::BigInt => "bigint".to_owned(),
            FieldType::Txt => "text".to_owned(),
            FieldType::Bool => "bit".to_owned(),
            FieldType::Dbl => "double".to_owned(),
            FieldType::AutoInc => "integer auto_increment".to_owned(),
        }
    }
}

/// SQLite type serializator
#[derive(Debug)]
pub struct Sqlite {}
impl TypeWriter for Sqlite {
    fn type_to_sql(&self, field_type:&FieldType) -> String {
        match field_type {
            FieldType::Int => "integer".to_owned(),
            FieldType::BigInt => "integer".to_owned(),
            FieldType::Txt => "text".to_owned(),
            FieldType::Bool => "integer".to_owned(),
            FieldType::Dbl => "real".to_owned(),
            FieldType::AutoInc => "autoincrement".to_owned(),
        }
    }
}