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
use expression::{Expression, AsExpression};
use expression::predicates::{Like, NotLike};
use types::{VarChar, Text};

pub trait VarCharExpressionMethods: Expression<SqlType=VarChar> + Sized {
    /// Returns a SQL `LIKE` expression
    fn like<T: AsExpression<VarChar>>(self, other: T) -> Like<Self, T::Expression> {
        Like::new(self.as_expression(), other.as_expression())
    }

    /// Returns a SQL `NOT LIKE` expression
    fn not_like<T: AsExpression<VarChar>>(self, other: T) -> NotLike<Self, T::Expression> {
        NotLike::new(self.as_expression(), other.as_expression())
    }
}

impl<T: Expression<SqlType=VarChar>> VarCharExpressionMethods for T {}

pub trait TextExpressionMethods: Expression<SqlType=Text> + Sized {
    /// Returns a SQL `LIKE` expression
    fn like<T: AsExpression<Text>>(self, other: T) -> Like<Self, T::Expression> {
        Like::new(self.as_expression(), other.as_expression())
    }

    /// Returns a SQL `NOT LIKE` expression
    fn not_like<T: AsExpression<Text>>(self, other: T) -> NotLike<Self, T::Expression> {
        NotLike::new(self.as_expression(), other.as_expression())
    }
}

impl<T: Expression<SqlType=Text>> TextExpressionMethods for T {}