use crate::{
Bool, Query, TypeMeta,
expression::{Expression, Scalar},
lower::LowerCtx,
};
pub struct Exists {
query: Query,
negated: bool,
}
#[qraft_expression_macro::as_expression]
impl Expression for Exists {
type Type = Bool;
fn lower(&self, ctx: &mut LowerCtx) -> usize {
let inner = ctx.lower_subquery_ref(&self.query);
ctx.lower_exists(self.negated, inner)
}
}
pub fn exists<T>(query: Scalar<T>) -> Exists
where
T: TypeMeta,
{
Exists {
query: query.inner,
negated: false,
}
}
pub fn not_exists<T>(query: Scalar<T>) -> Exists
where
T: TypeMeta,
{
Exists {
query: query.inner,
negated: true,
}
}