Skip to main content

rjango_contrib_postgres/
aggregates.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
4pub struct ArrayAgg {
5    pub expression: String,
6    pub distinct: bool,
7}
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub struct StringAgg {
11    pub expression: String,
12    pub delimiter: String,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct JSONBAgg {
17    pub expression: String,
18}
19
20#[cfg(test)]
21mod tests {
22    use super::{ArrayAgg, JSONBAgg, StringAgg};
23
24    #[test]
25    fn array_agg_construction_preserves_expression() {
26        let aggregate = ArrayAgg {
27            expression: "tags".to_string(),
28            distinct: true,
29        };
30
31        assert_eq!(aggregate.expression, "tags");
32        assert!(aggregate.distinct);
33    }
34
35    #[test]
36    fn string_agg_construction_preserves_delimiter() {
37        let aggregate = StringAgg {
38            expression: "title".to_string(),
39            delimiter: ", ".to_string(),
40        };
41
42        assert_eq!(aggregate.expression, "title");
43        assert_eq!(aggregate.delimiter, ", ");
44    }
45
46    #[test]
47    fn jsonb_agg_construction_preserves_expression() {
48        let aggregate = JSONBAgg {
49            expression: "payload".to_string(),
50        };
51
52        assert_eq!(aggregate.expression, "payload");
53    }
54}