teo_sql_connector/schema/
dialect.rs

1use teo_runtime::database::mysql::r#type::MySQLType;
2use teo_runtime::database::postgres::r#type::PostgreSQLType;
3use teo_runtime::database::r#type::DatabaseType;
4use teo_runtime::database::sqlite::r#type::SQLiteType;
5
6#[derive(Debug, PartialEq, Copy, Clone)]
7pub enum SQLDialect {
8    MySQL,
9    PostgreSQL,
10    SQLite,
11    MSSQL,
12}
13
14impl SQLDialect {
15
16    pub(crate) fn escape(&self) -> &'static str {
17        match self {
18            SQLDialect::PostgreSQL => "\"",
19            _ => "`",
20        }
21    }
22
23    pub(crate) fn is_postgres(&self) -> bool {
24        match self {
25            SQLDialect::PostgreSQL => true,
26            _ => false,
27        }
28    }
29
30    pub(crate) fn is_mysql(&self) -> bool {
31        match self {
32            SQLDialect::MySQL => true,
33            _ => false,
34        }
35    }
36
37    pub(crate) fn is_sqlite(&self) -> bool {
38        match self {
39            SQLDialect::SQLite => true,
40            _ => false,
41        }
42    }
43
44    pub(crate) fn float64_type(&self) -> DatabaseType {
45        match self {
46            SQLDialect::MySQL => DatabaseType::MySQLType(MySQLType::Double),
47            SQLDialect::PostgreSQL => DatabaseType::PostgreSQLType(PostgreSQLType::DoublePrecision),
48            SQLDialect::SQLite => DatabaseType::SQLiteType(SQLiteType::Real),
49            SQLDialect::MSSQL => panic!(),
50        }
51    }
52
53    pub(crate) fn int64_type(&self) -> DatabaseType {
54        match self {
55            SQLDialect::MySQL => DatabaseType::MySQLType(MySQLType::Int(None, true)),
56            SQLDialect::PostgreSQL => DatabaseType::PostgreSQLType(PostgreSQLType::Integer),
57            SQLDialect::SQLite => DatabaseType::SQLiteType(SQLiteType::Integer),
58            SQLDialect::MSSQL => panic!(),
59        }
60    }
61}