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