use crate::dsl;
use crate::expression::grouped::Grouped;
use crate::expression::operators::{And, Or};
use crate::expression::{AsExpression, Expression, TypedExpressionType};
use crate::sql_types::{self, BoolOrNullableBool, SqlType};
pub trait BoolExpressionMethods: Expression + Sized {
fn and<T, ST>(self, other: T) -> dsl::And<Self, T, ST>
where
Self::SqlType: SqlType,
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
T: AsExpression<ST>,
And<Self, T::Expression>: Expression,
{
Grouped(And::new(self, other.as_expression()))
}
fn or<T, ST>(self, other: T) -> dsl::Or<Self, T, ST>
where
Self::SqlType: SqlType,
ST: SqlType + TypedExpressionType + BoolOrNullableBool,
T: AsExpression<ST>,
Or<Self, T::Expression>: Expression,
{
Grouped(Or::new(self, other.as_expression()))
}
}
impl<T> BoolExpressionMethods for T
where
T: Expression,
T::SqlType: BoolOrNullableBool,
{
}
pub trait PreferredBoolSqlType {
type PreferredSqlType;
}
impl<E: Expression> PreferredBoolSqlType for E
where
E::SqlType: BoolOrNullableBool,
{
type PreferredSqlType = <E as Expression>::SqlType;
}
impl PreferredBoolSqlType for bool {
type PreferredSqlType = sql_types::Bool;
}
impl PreferredBoolSqlType for &bool {
type PreferredSqlType = sql_types::Bool;
}
impl PreferredBoolSqlType for &&bool {
type PreferredSqlType = sql_types::Bool;
}
impl PreferredBoolSqlType for Option<bool> {
type PreferredSqlType = sql_types::Nullable<sql_types::Bool>;
}
impl PreferredBoolSqlType for &Option<bool> {
type PreferredSqlType = sql_types::Nullable<sql_types::Bool>;
}
impl PreferredBoolSqlType for &&Option<bool> {
type PreferredSqlType = sql_types::Nullable<sql_types::Bool>;
}