diesel/expression/
subselect.rs
1use std::marker::PhantomData;
2
3use crate::expression::array_comparison::MaybeEmpty;
4use crate::expression::*;
5use crate::query_builder::*;
6use crate::result::QueryResult;
7
8#[derive(Debug, Copy, Clone, QueryId)]
9pub struct Subselect<T, ST> {
10 values: T,
11 _sql_type: PhantomData<ST>,
12}
13
14impl<T, ST> Subselect<T, ST> {
15 pub(crate) fn new(values: T) -> Self {
16 Self {
17 values,
18 _sql_type: PhantomData,
19 }
20 }
21}
22
23impl<T: SelectQuery, ST> Expression for Subselect<T, ST>
24where
25 ST: SqlType + TypedExpressionType,
26{
27 type SqlType = ST;
28}
29
30impl<T, ST> MaybeEmpty for Subselect<T, ST> {
31 fn is_empty(&self) -> bool {
32 false
33 }
34}
35
36impl<T, ST, QS> SelectableExpression<QS> for Subselect<T, ST>
37where
38 Subselect<T, ST>: AppearsOnTable<QS>,
39 T: ValidSubselect<QS>,
40{
41}
42
43impl<T, ST, QS> AppearsOnTable<QS> for Subselect<T, ST>
44where
45 Subselect<T, ST>: Expression,
46 T: ValidSubselect<QS>,
47{
48}
49
50impl<T, ST, GB> ValidGrouping<GB> for Subselect<T, ST> {
54 type IsAggregate = is_aggregate::Never;
55}
56
57impl<T, ST, DB> QueryFragment<DB> for Subselect<T, ST>
58where
59 DB: Backend,
60 T: QueryFragment<DB>,
61{
62 fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, DB>) -> QueryResult<()> {
63 self.values.walk_ast(out.reborrow())?;
64 Ok(())
65 }
66}
67
68pub trait ValidSubselect<QS> {}