flusso_query/handles/
sort.rs1use serde_json::{Map, Value};
5
6#[derive(Debug, Clone, Copy)]
8pub enum SortOrder {
9 Asc,
11 Desc,
13}
14
15impl SortOrder {
16 pub(crate) fn as_str(self) -> &'static str {
17 match self {
18 SortOrder::Asc => "asc",
19 SortOrder::Desc => "desc",
20 }
21 }
22}
23
24#[derive(Debug, Clone)]
27pub struct Sort {
28 value: Value,
29}
30
31impl Sort {
32 pub(crate) fn new(field: &str, order: SortOrder) -> Self {
34 let mut order_body = Map::new();
35 order_body.insert(
36 "order".to_string(),
37 Value::String(order.as_str().to_string()),
38 );
39 let mut outer = Map::new();
40 outer.insert(field.to_string(), Value::Object(order_body));
41 Self {
42 value: Value::Object(outer),
43 }
44 }
45
46 pub(crate) fn raw(value: Value) -> Self {
48 Self { value }
49 }
50
51 pub(crate) fn to_value(&self) -> Value {
52 self.value.clone()
53 }
54}