toasty_core/stmt/order_by.rs
1use super::OrderByExpr;
2
3/// An `ORDER BY` clause containing one or more ordering expressions.
4///
5/// # Examples
6///
7/// ```ignore
8/// use toasty_core::stmt::{OrderBy, OrderByExpr, Direction, Expr};
9///
10/// let order = OrderBy {
11/// exprs: vec![OrderByExpr {
12/// expr: Expr::null(),
13/// order: Some(Direction::Asc),
14/// }],
15/// };
16/// ```
17#[derive(Debug, Clone, PartialEq)]
18pub struct OrderBy {
19 /// The list of ordering expressions, applied in order.
20 pub exprs: Vec<OrderByExpr>,
21}
22
23impl OrderBy {
24 /// Flips the direction of each [`OrderByExpr`] that makes up this [`OrderBy`].
25 pub fn reverse(&mut self) {
26 for expr in &mut self.exprs {
27 expr.reverse();
28 }
29 }
30}
31
32impl From<OrderByExpr> for OrderBy {
33 fn from(value: OrderByExpr) -> Self {
34 Self { exprs: vec![value] }
35 }
36}