1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use backend::Backend;
use expression::{Expression, NonAggregate};
use query_builder::*;
use result::QueryResult;
use sql_types::Bool;
pub fn exists<T>(query: T) -> Exists<T> {
Exists(query)
}
#[derive(Debug, Clone, Copy, QueryId)]
pub struct Exists<T>(T);
impl<T> Expression for Exists<T>
where
T: Expression,
{
type SqlType = Bool;
}
impl<T> NonAggregate for Exists<T> {}
impl<T, DB> QueryFragment<DB> for Exists<T>
where
DB: Backend,
T: QueryFragment<DB>,
{
fn walk_ast(&self, mut out: AstPass<DB>) -> QueryResult<()> {
out.push_sql("EXISTS (");
self.0.walk_ast(out.reborrow())?;
out.push_sql(")");
Ok(())
}
}
impl_selectable_expression!(Exists<T>);