1 use super::methods::LimitDsl;
2 use dsl::Limit;
3 use expression::grouped::Grouped;
4 use expression::subselect::Subselect;
5 use query_builder::SelectQuery;
6 use sql_types::{IntoNullable, SingleValue};
7 
8 /// The `single_value` method
9 ///
10 /// This trait should not be relied on directly by most apps. Its behavior is
11 /// provided by [`QueryDsl`]. However, you may need a where clause on this trait
12 /// to call `single_value` from generic code.
13 ///
14 /// [`QueryDsl`]: ../trait.QueryDsl.html
15 pub trait SingleValueDsl {
16     /// The type returned by `.single_value`.
17     type Output;
18 
19     /// See the trait documentation.
single_value(self) -> Self::Output20     fn single_value(self) -> Self::Output;
21 }
22 
23 impl<T, ST> SingleValueDsl for T
24 where
25     Self: SelectQuery<SqlType = ST> + LimitDsl,
26     ST: IntoNullable,
27     ST::Nullable: SingleValue,
28 {
29     type Output = Grouped<Subselect<Limit<Self>, ST::Nullable>>;
30 
single_value(self) -> Self::Output31     fn single_value(self) -> Self::Output {
32         Grouped(Subselect::new(self.limit(1)))
33     }
34 }
35