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}
18
19/// Query Order (ASC / DESC)
20#[derive(Debug, Clone)]
21pub enum QueryOrder {
22    /// Ascending
23    Asc,
24    /// Descending
25    Desc,
26}
27
28impl ToSqlite for QueryOrder {
29    fn to_sqlite(&self) -> String {
30        match self {
31            QueryOrder::Asc => String::from("ASC"),
32            QueryOrder::Desc => String::from("DESC"),
33        }
34    }
35}
36
37/// Query Condition (EQ, NE, etc.)
38#[derive(Debug, Clone, Default)]
39pub enum QueryCondition {
40    /// Equal
41    #[default]
42    Eq,
43    /// Not Equal
44    Ne,
45    /// Like
46    Like,
47    /// Greater Than
48    Gt,
49    /// Less Than
50    Lt,
51    /// Greater Than or Equal to
52    Gte,
53    /// Less Than or Equal to
54    Lte,
55}
56
57impl ToSqlite for QueryCondition {
58    fn to_sqlite(&self) -> String {
59        match self {
60            QueryCondition::Eq => String::from("="),
61            QueryCondition::Ne => String::from("!="),
62            QueryCondition::Like => String::from("LIKE"),
63            QueryCondition::Gt => String::from(">"),
64            QueryCondition::Lt => String::from("<"),
65            QueryCondition::Gte => String::from(">="),
66            QueryCondition::Lte => String::from("<="),
67        }
68    }
69}
70
71/// Where Condition (AND, OR)
72#[derive(Debug, Clone, Default)]
73pub enum WhereCondition {
74    /// And condition
75    #[default]
76    And,
77    /// Or condition
78    Or,
79}
80
81impl WhereCondition {
82    /// Get all where conditions as a vector of strings
83    pub fn all() -> Vec<String> {
84        vec![
85            WhereCondition::And.to_sqlite(),
86            WhereCondition::Or.to_sqlite(),
87        ]
88    }
89}
90
91impl ToSqlite for WhereCondition {
92    fn to_sqlite(&self) -> String {
93        match self {
94            WhereCondition::And => String::from("AND"),
95            WhereCondition::Or => String::from("OR"),
96        }
97    }
98}