geekorm_core/builder/
models.rs

1use crate::ToSqlite;
2
3/// Query Type (CREATE, SELECT, etc.)
4#[derive(Debug, Clone, Default, PartialEq, Eq)]
5pub enum QueryType {
6    /// Create a new table
7    Create,
8    /// Select data from a table
9    #[default]
10    Select,
11    /// Insert data into a table
12    Insert,
13    /// Update data in a table
14    Update,
15    /// Delete data from a table
16    Delete,
17    /// Batch query
18    Batch,
19}
20
21/// Query Order (ASC / DESC)
22#[derive(Debug, Clone)]
23pub enum QueryOrder {
24    /// Ascending
25    Asc,
26    /// Descending
27    Desc,
28}
29
30impl ToSqlite for QueryOrder {
31    fn to_sqlite(&self) -> String {
32        match self {
33            QueryOrder::Asc => String::from("ASC"),
34            QueryOrder::Desc => String::from("DESC"),
35        }
36    }
37}
38
39/// Query Condition (EQ, NE, etc.)
40#[derive(Debug, Clone, Default)]
41pub enum QueryCondition {
42    /// Equal
43    #[default]
44    Eq,
45    /// Not Equal
46    Ne,
47    /// Like
48    Like,
49    /// Greater Than
50    Gt,
51    /// Less Than
52    Lt,
53    /// Greater Than or Equal to
54    Gte,
55    /// Less Than or Equal to
56    Lte,
57}
58
59impl ToSqlite for QueryCondition {
60    fn to_sqlite(&self) -> String {
61        match self {
62            QueryCondition::Eq => String::from("="),
63            QueryCondition::Ne => String::from("!="),
64            QueryCondition::Like => String::from("LIKE"),
65            QueryCondition::Gt => String::from(">"),
66            QueryCondition::Lt => String::from("<"),
67            QueryCondition::Gte => String::from(">="),
68            QueryCondition::Lte => String::from("<="),
69        }
70    }
71}
72
73/// Where Condition (AND, OR)
74#[derive(Debug, Clone, Default)]
75pub enum WhereCondition {
76    /// And condition
77    #[default]
78    And,
79    /// Or condition
80    Or,
81}
82
83impl WhereCondition {
84    /// Get all where conditions as a vector of strings
85    pub fn all() -> Vec<String> {
86        vec![
87            WhereCondition::And.to_sqlite(),
88            WhereCondition::Or.to_sqlite(),
89        ]
90    }
91}
92
93impl ToSqlite for WhereCondition {
94    fn to_sqlite(&self) -> String {
95        match self {
96            WhereCondition::And => String::from("AND"),
97            WhereCondition::Or => String::from("OR"),
98        }
99    }
100}