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