grafbase_sql_ast/ast/
conjunctive.rs

1use crate::ast::{ConditionTree, Expression};
2
3/// `AND`, `OR` and `NOT` conjunctive implementations.
4pub trait Conjunctive<'a> {
5    /// Builds an `AND` condition having `self` as the left leaf and `other` as the right.
6    fn and<E>(self, other: E) -> ConditionTree<'a>
7    where
8        E: Into<Expression<'a>>;
9
10    /// Builds an `OR` condition having `self` as the left leaf and `other` as the right.
11    fn or<E>(self, other: E) -> ConditionTree<'a>
12    where
13        E: Into<Expression<'a>>;
14
15    /// Builds a `NOT` condition having `self` as the condition.
16    fn not(self) -> ConditionTree<'a>;
17}
18
19impl<'a, T> Conjunctive<'a> for T
20where
21    T: Into<Expression<'a>>,
22{
23    fn and<E>(self, other: E) -> ConditionTree<'a>
24    where
25        E: Into<Expression<'a>>,
26    {
27        ConditionTree::And(vec![self.into(), other.into()])
28    }
29
30    fn or<E>(self, other: E) -> ConditionTree<'a>
31    where
32        E: Into<Expression<'a>>,
33    {
34        ConditionTree::Or(vec![self.into(), other.into()])
35    }
36
37    fn not(self) -> ConditionTree<'a> {
38        ConditionTree::not(self.into())
39    }
40}