1use super::methods::LimitDsl;
2use crate::dsl::Limit;
3use crate::expression::grouped::Grouped;
4use crate::expression::subselect::Subselect;
5use crate::query_builder::SelectQuery;
6use crate::sql_types::IntoNullable;
78/// 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`]: crate::QueryDsl
15pub trait SingleValueDsl {
16/// The type returned by `.single_value`.
17type Output;
1819/// See the trait documentation.
20fn single_value(self) -> Self::Output;
21}
2223impl<T> SingleValueDsl for T
24where
25Self: SelectQuery + LimitDsl,
26 <Self as SelectQuery>::SqlType: IntoNullable,
27{
28type Output =
29 Grouped<Subselect<Limit<Self>, <<Self as SelectQuery>::SqlType as IntoNullable>::Nullable>>;
3031fn single_value(self) -> Self::Output {
32 Grouped(Subselect::new(self.limit(1)))
33 }
34}