a3s_orm/compiler/
dialect.rs1pub trait Dialect: Send + Sync {
2 fn name(&self) -> &'static str;
3 fn identifier_quote(&self) -> char;
4 fn placeholder(&self, index: usize) -> String;
5 fn supports_returning(&self) -> bool;
6 fn supports_on_conflict(&self) -> bool;
7 fn supports_update_from(&self) -> bool {
9 false
10 }
11 fn supports_select_row_locking(&self) -> bool {
13 false
14 }
15 fn supports_table_locking(&self) -> bool {
17 false
18 }
19}
20
21#[derive(Clone, Copy, Debug, Default)]
22pub struct PostgresDialect;
23
24impl Dialect for PostgresDialect {
25 fn name(&self) -> &'static str {
26 "PostgreSQL"
27 }
28
29 fn identifier_quote(&self) -> char {
30 '"'
31 }
32
33 fn placeholder(&self, index: usize) -> String {
34 format!("${index}")
35 }
36
37 fn supports_returning(&self) -> bool {
38 true
39 }
40
41 fn supports_on_conflict(&self) -> bool {
42 true
43 }
44
45 fn supports_update_from(&self) -> bool {
46 true
47 }
48
49 fn supports_select_row_locking(&self) -> bool {
50 true
51 }
52
53 fn supports_table_locking(&self) -> bool {
54 true
55 }
56}
57
58#[derive(Clone, Copy, Debug, Default)]
59pub struct SqliteDialect;
60
61impl Dialect for SqliteDialect {
62 fn name(&self) -> &'static str {
63 "SQLite"
64 }
65
66 fn identifier_quote(&self) -> char {
67 '"'
68 }
69
70 fn placeholder(&self, _index: usize) -> String {
71 "?".to_string()
72 }
73
74 fn supports_returning(&self) -> bool {
75 true
76 }
77
78 fn supports_on_conflict(&self) -> bool {
79 true
80 }
81
82 fn supports_update_from(&self) -> bool {
83 true
84 }
85}
86
87#[derive(Clone, Copy, Debug, Default)]
88pub struct MysqlDialect;
89
90impl Dialect for MysqlDialect {
91 fn name(&self) -> &'static str {
92 "MySQL"
93 }
94
95 fn identifier_quote(&self) -> char {
96 '`'
97 }
98
99 fn placeholder(&self, _index: usize) -> String {
100 "?".to_string()
101 }
102
103 fn supports_returning(&self) -> bool {
104 false
105 }
106
107 fn supports_on_conflict(&self) -> bool {
108 false
109 }
110}