use super::operators::*;
use expression::{AsExpression, Expression};
use sql_types::{Array, Nullable, Text};
pub trait PgExpressionMethods: Expression + Sized {
fn is_not_distinct_from<T>(self, other: T) -> IsNotDistinctFrom<Self, T::Expression>
where
T: AsExpression<Self::SqlType>,
{
IsNotDistinctFrom::new(self, other.as_expression())
}
fn is_distinct_from<T>(self, other: T) -> IsDistinctFrom<Self, T::Expression>
where
T: AsExpression<Self::SqlType>,
{
IsDistinctFrom::new(self, other.as_expression())
}
}
impl<T: Expression> PgExpressionMethods for T {}
use super::date_and_time::{AtTimeZone, DateTimeLike};
use sql_types::VarChar;
pub trait PgTimestampExpressionMethods: Expression + Sized {
fn at_time_zone<T>(self, timezone: T) -> AtTimeZone<Self, T::Expression>
where
T: AsExpression<VarChar>,
{
AtTimeZone::new(self, timezone.as_expression())
}
}
impl<T: Expression> PgTimestampExpressionMethods for T where T::SqlType: DateTimeLike {}
pub trait PgArrayExpressionMethods<ST>: Expression<SqlType = Array<ST>> + Sized {
fn overlaps_with<T>(self, other: T) -> OverlapsWith<Self, T::Expression>
where
T: AsExpression<Self::SqlType>,
{
OverlapsWith::new(self, other.as_expression())
}
fn contains<T>(self, other: T) -> Contains<Self, T::Expression>
where
T: AsExpression<Self::SqlType>,
{
Contains::new(self, other.as_expression())
}
fn is_contained_by<T>(self, other: T) -> IsContainedBy<Self, T::Expression>
where
T: AsExpression<Self::SqlType>,
{
IsContainedBy::new(self, other.as_expression())
}
}
impl<T, ST> PgArrayExpressionMethods<ST> for T where T: Expression<SqlType = Array<ST>> {}
use expression::operators::{Asc, Desc};
pub trait PgSortExpressionMethods: Sized {
fn nulls_first(self) -> NullsFirst<Self> {
NullsFirst::new(self)
}
fn nulls_last(self) -> NullsLast<Self> {
NullsLast::new(self)
}
}
impl<T> PgSortExpressionMethods for Asc<T> {}
impl<T> PgSortExpressionMethods for Desc<T> {}
pub trait PgTextExpressionMethods: Expression + Sized {
fn ilike<T: AsExpression<Text>>(self, other: T) -> ILike<Self, T::Expression> {
ILike::new(self.as_expression(), other.as_expression())
}
fn not_ilike<T: AsExpression<Text>>(self, other: T) -> NotILike<Self, T::Expression> {
NotILike::new(self.as_expression(), other.as_expression())
}
}
#[doc(hidden)]
pub trait TextOrNullableText {}
impl TextOrNullableText for Text {}
impl TextOrNullableText for Nullable<Text> {}
impl<T> PgTextExpressionMethods for T
where
T: Expression,
T::SqlType: TextOrNullableText,
{
}