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