1use std::{
5 fmt,
6 fmt::{Display, Formatter},
7};
8
9use reifydb_codec::key::sort::SortOrder;
10use reifydb_value::fragment::Fragment;
11use serde::{Deserialize, Serialize};
12
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14pub enum SortDirection {
15 Asc,
16 Desc,
17}
18
19impl From<SortDirection> for SortOrder {
20 fn from(direction: SortDirection) -> Self {
21 match direction {
22 SortDirection::Asc => SortOrder::Asc,
23 SortDirection::Desc => SortOrder::Desc,
24 }
25 }
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct SortKey {
30 pub column: Fragment,
31 pub direction: SortDirection,
32}
33
34impl Display for SortDirection {
35 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
36 match self {
37 SortDirection::Asc => write!(f, "ASC"),
38 SortDirection::Desc => write!(f, "DESC"),
39 }
40 }
41}
42
43impl Display for SortKey {
44 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
45 write!(f, "{} {}", self.column.fragment(), self.direction)
46 }
47}