use crate::values::PostgresValue;
use drizzle_core::expr::{AggregateKind, ComparisonOperand, Expr, NonNull, SQLExpr};
use drizzle_core::scope::Arg;
use drizzle_core::sql::{SQLChunk, Token};
use drizzle_types::postgres::types::Boolean;
use drizzle_types::{Compatible, Textual};
type IlikeExpr<'a, E, P> = SQLExpr<
'a,
PostgresValue<'a>,
Boolean,
NonNull,
<<E as Expr<'a, PostgresValue<'a>>>::Aggregate as AggregateKind>::Or<
<P as ComparisonOperand<'a, PostgresValue<'a>, E>>::Aggregate,
>,
(
Arg<
<E as Expr<'a, PostgresValue<'a>>>::Nullable,
<E as drizzle_core::expr::ExprSources>::Sources,
>,
Arg<
<P as ComparisonOperand<'a, PostgresValue<'a>, E>>::Nullable,
<P as ComparisonOperand<'a, PostgresValue<'a>, E>>::Sources,
>,
),
>;
pub fn ilike<'a, E, P>(expr: E, pattern: P) -> IlikeExpr<'a, E, P>
where
E: Expr<'a, PostgresValue<'a>>,
P: ComparisonOperand<'a, PostgresValue<'a>, E>,
E::SQLType: Compatible<P::SQLType> + Textual,
P::SQLType: Textual,
{
SQLExpr::new(
expr.to_sql()
.push(SQLChunk::Raw("ILIKE".into()))
.append(pattern.into_comparison_sql()),
)
}
pub fn not_ilike<'a, E, P>(expr: E, pattern: P) -> IlikeExpr<'a, E, P>
where
E: Expr<'a, PostgresValue<'a>>,
P: ComparisonOperand<'a, PostgresValue<'a>, E>,
E::SQLType: Compatible<P::SQLType> + Textual,
P::SQLType: Textual,
{
SQLExpr::new(
expr.to_sql()
.push(Token::NOT)
.push(SQLChunk::Raw("ILIKE".into()))
.append(pattern.into_comparison_sql()),
)
}