Debian Codegraph @

src/query_dsl/order_dsl.rs

raw
1 use crate::expression::Expression;
2 use crate::query_source::Table;
3
4 /// The `order` method
5 ///
6 /// This trait should not be relied on directly by most apps. Its behavior is
7 /// provided by [`QueryDsl`]. However, you may need a where clause on this trait
8 /// to call `order` from generic code.
9 ///
10 /// [`QueryDsl`]: crate::QueryDsl
11 pub trait OrderDsl<Expr: Expression> {
12 /// The type returned by `.order`.
13 type Output;
14
15 /// See the trait documentation.
16 fn order(self, expr: Expr) -> Self::Output;
17 }
18
19 impl<T, Expr> OrderDsl<Expr> for T
20 where
21 Expr: Expression,
22 T: Table,
23 T::Query: OrderDsl<Expr>,
24 {
25 type Output = <T::Query as OrderDsl<Expr>>::Output;
26
27 fn order(self, expr: Expr) -> Self::Output {
28 self.as_query().order(expr)
29 }
30 }
31
32 /// The `then_order_by` method
33 ///
34 /// This trait should not be relied on directly by most apps. Its behavior is
35 /// provided by [`QueryDsl`]. However, you may need a where clause on this trait
36 /// to call `then_order_by` from generic code.
37 ///
38 /// [`QueryDsl`]: crate::QueryDsl
39 pub trait ThenOrderDsl<Expr> {
40 /// The type returned by `.then_order_by`.
41 type Output;
42
43 /// See the trait documentation.
44 fn then_order_by(self, expr: Expr) -> Self::Output;
45 }
46
47 impl<T, Expr> ThenOrderDsl<Expr> for T
48 where
49 Expr: Expression,
50 T: Table,
51 T::Query: ThenOrderDsl<Expr>,
52 {
53 type Output = <T::Query as ThenOrderDsl<Expr>>::Output;
54
55 fn then_order_by(self, expr: Expr) -> Self::Output {
56 self.as_query().then_order_by(expr)
57 }
58 }
59
60 #[diagnostic::on_unimplemented(
61 message = "invalid order of elements in your `DISTINCT ON` clause in relation to your `ORDER BY` clause",
62 note = "the elements in your `DISTINCT ON` clause needs to match the elements \
63 in your `ORDER BY` clause up to which clause contains less elements"
64 )]
65 pub trait ValidOrderingForDistinct<D> {}