dactyl_db/query/
dialect.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum Dialect {
11 Sqlite,
13 Postgres,
15}
16
17#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22pub enum Construct {
23 JsonEach,
25 JsonTree,
26 WithoutRowId,
27 Strict,
28 JsonArrowText,
30 JsonArrow,
31 JsonContains,
32 JsonContained,
33 JsonExists,
34 Jsonb,
35 Returning,
36 Ilike,
37 GenRandomUuid,
38 NowFn,
39}
40
41impl Construct {
42 pub fn lexeme(self) -> &'static str {
44 match self {
45 Construct::JsonEach => "json_each",
46 Construct::JsonTree => "json_tree",
47 Construct::WithoutRowId => "without rowid",
48 Construct::Strict => "strict",
49 Construct::JsonArrowText => "->>",
50 Construct::JsonArrow => "->",
51 Construct::JsonContains => "@>",
52 Construct::JsonContained => "<@",
53 Construct::JsonExists => "?",
54 Construct::Jsonb => "jsonb",
55 Construct::Returning => "returning",
56 Construct::Ilike => "ilike",
57 Construct::GenRandomUuid => "gen_random_uuid",
58 Construct::NowFn => "now",
59 }
60 }
61
62 pub fn dialect(self) -> Dialect {
64 match self {
65 Construct::JsonEach
66 | Construct::JsonTree
67 | Construct::WithoutRowId
68 | Construct::Strict => Dialect::Sqlite,
69 _ => Dialect::Postgres,
70 }
71 }
72
73 pub fn supported_by(self, dialect: Dialect) -> bool {
75 self.dialect() == dialect
76 }
77}
78
79pub fn first_unsupported(constructs: &[Construct], dialect: Dialect) -> Option<Construct> {
84 constructs
85 .iter()
86 .copied()
87 .find(|c| !c.supported_by(dialect))
88}