dml_tools/
type_writers.rs1use crate::sql::{TypeWriter, FieldType, ObjectPath};
2
3#[derive(Debug)]
5pub struct Postgresql {}
6impl TypeWriter for Postgresql {
7 fn id(&self) -> &str { "pgsql" }
8 fn field_type(&self, field_type:&FieldType) -> String {
9 match field_type {
10 FieldType::Int => "int".to_owned(),
11 FieldType::BigInt => "bigint".to_owned(),
12 FieldType::Txt => "text".to_owned(),
13 FieldType::Bool => "bool".to_owned(),
14 FieldType::Dbl => "double precision".to_owned(),
15 FieldType::AutoInc => "serial".to_owned(),
16 }
17 }
18 fn supports_sequences(&self) -> bool { true }
19}
20
21#[derive(Debug)]
23pub struct Mysql {}
24impl TypeWriter for Mysql {
25 fn id(&self) -> &str { "mysql" }
26 fn field_type(&self, field_type:&FieldType) -> String {
27 match field_type {
28 FieldType::Int => "int".to_owned(),
29 FieldType::BigInt => "bigint".to_owned(),
30 FieldType::Txt => "text".to_owned(),
31 FieldType::Bool => "bit".to_owned(),
32 FieldType::Dbl => "double".to_owned(),
33 FieldType::AutoInc => "integer auto_increment".to_owned(),
34 }
35 }
36}
37
38#[derive(Debug)]
40pub struct Sqlite {}
41impl TypeWriter for Sqlite {
42 fn id(&self) -> &str { "sqlite" }
43 fn field_type(&self, field_type:&FieldType) -> String {
44 match field_type {
45 FieldType::Int => "integer".to_owned(),
46 FieldType::BigInt => "integer".to_owned(),
47 FieldType::Txt => "text".to_owned(),
48 FieldType::Bool => "integer".to_owned(),
49 FieldType::Dbl => "real".to_owned(),
50 FieldType::AutoInc => "integer primary key autoincrement".to_owned(),
51 }
52 }
53 fn schema(&self, op:&ObjectPath) -> String {
54 op.name.to_owned()
55 }
56 fn index_type(&self) -> String { "".to_string() }
57 fn supports_schemas(&self) -> bool { false }
58 fn supports_permissions(&self) -> bool { false }
59 fn supports_auto_increment(&self) -> bool { false }
60}