reifydb_core/
sort.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use std::{
5	fmt,
6	fmt::{Display, Formatter},
7};
8
9use reifydb_type::Fragment;
10use serde::{Deserialize, Serialize};
11
12#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
13pub enum SortDirection {
14	Asc,
15	Desc,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct SortKey {
20	pub column: Fragment,
21	pub direction: SortDirection,
22}
23
24impl Display for SortDirection {
25	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
26		match self {
27			SortDirection::Asc => write!(f, "ASC"),
28			SortDirection::Desc => write!(f, "DESC"),
29		}
30	}
31}
32
33impl Display for SortKey {
34	fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
35		write!(f, "{} {}", self.column.fragment(), self.direction)
36	}
37}