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
51
52
53
54
55
56
57
58
59
60
61
use teo_runtime::database::mysql::r#type::MySQLType;
use teo_runtime::database::postgres::r#type::PostgreSQLType;
use teo_runtime::database::r#type::DatabaseType;
use teo_runtime::database::sqlite::r#type::SQLiteType;

#[derive(Debug, PartialEq, Copy, Clone)]
pub enum SQLDialect {
    MySQL,
    PostgreSQL,
    SQLite,
    MSSQL,
}

impl SQLDialect {

    pub(crate) fn escape(&self) -> &'static str {
        match self {
            SQLDialect::PostgreSQL => "\"",
            _ => "`",
        }
    }

    pub(crate) fn is_postgres(&self) -> bool {
        match self {
            SQLDialect::PostgreSQL => true,
            _ => false,
        }
    }

    pub(crate) fn is_mysql(&self) -> bool {
        match self {
            SQLDialect::MySQL => true,
            _ => false,
        }
    }

    pub(crate) fn is_sqlite(&self) -> bool {
        match self {
            SQLDialect::SQLite => true,
            _ => false,
        }
    }

    pub(crate) fn float64_type(&self) -> DatabaseType {
        match self {
            SQLDialect::MySQL => DatabaseType::MySQLType(MySQLType::Double),
            SQLDialect::PostgreSQL => DatabaseType::PostgreSQLType(PostgreSQLType::DoublePrecision),
            SQLDialect::SQLite => DatabaseType::SQLiteType(SQLiteType::Real),
            SQLDialect::MSSQL => panic!(),
        }
    }

    pub(crate) fn int64_type(&self) -> DatabaseType {
        match self {
            SQLDialect::MySQL => DatabaseType::MySQLType(MySQLType::Int(None, true)),
            SQLDialect::PostgreSQL => DatabaseType::PostgreSQLType(PostgreSQLType::Integer),
            SQLDialect::SQLite => DatabaseType::SQLiteType(SQLiteType::Integer),
            SQLDialect::MSSQL => panic!(),
        }
    }
}