elif_orm/query/
ordering.rs

1//! Query Builder ORDER BY, GROUP BY, HAVING operations
2
3use serde_json::Value;
4use super::builder::QueryBuilder;
5use super::types::*;
6
7impl<M> QueryBuilder<M> {
8    /// Add ORDER BY clause (ascending)
9    pub fn order_by(mut self, column: &str) -> Self {
10        self.order_by.push((column.to_string(), OrderDirection::Asc));
11        self
12    }
13
14    /// Add ORDER BY clause (descending)
15    pub fn order_by_desc(mut self, column: &str) -> Self {
16        self.order_by.push((column.to_string(), OrderDirection::Desc));
17        self
18    }
19
20    /// Add GROUP BY clause
21    pub fn group_by(mut self, column: &str) -> Self {
22        self.group_by.push(column.to_string());
23        self
24    }
25
26    /// Add HAVING clause with equals
27    pub fn having_eq<T: Into<Value>>(mut self, column: &str, value: T) -> Self {
28        self.having_conditions.push(WhereCondition {
29            column: column.to_string(),
30            operator: QueryOperator::Equal,
31            value: Some(value.into()),
32            values: Vec::new(),
33        });
34        self
35    }
36    
37    /// Add HAVING clause with custom operator and value  
38    pub fn having<T: Into<Value>>(mut self, column: &str, operator: QueryOperator, value: T) -> Self {
39        self.having_conditions.push(WhereCondition {
40            column: column.to_string(),
41            operator,
42            value: Some(value.into()),
43            values: Vec::new(),
44        });
45        self
46    }
47    
48    /// Add raw HAVING clause
49    pub fn having_raw(mut self, raw_condition: &str) -> Self {
50        self.having_conditions.push(WhereCondition {
51            column: "".to_string(), // Empty column for raw conditions
52            operator: QueryOperator::Raw,
53            value: Some(Value::String(raw_condition.to_string())),
54            values: Vec::new(),
55        });
56        self
57    }
58}