use super::{SqlTextComparison, push_slots};
use crate::comparison::{
At, Backend, ComplexComparison, TextMatch,
sql::{Carrier, like_pattern, not_wrapped, push_column},
};
impl<V> ComplexComparison<sqlx::Postgres> for SqlTextComparison<V, sqlx::Postgres>
where
V: Carrier<sqlx::Postgres> + AsRef<str>,
{
#[inline]
fn conjuncts(&self) -> usize {
Self::conjuncts(self)
}
fn apply<'q>(
&'q self,
at: At<'_>,
mut builder: <sqlx::Postgres as Backend>::Builder<'q>,
) -> Result<<sqlx::Postgres as Backend>::Builder<'q>, <sqlx::Postgres as Backend>::Error> {
push_slots(self, at, &mut builder, push_text_match);
Ok(builder)
}
}
fn push_text_match<V>(
qb: &mut sqlx::QueryBuilder<sqlx::Postgres>,
at: At<'_>,
kind: TextMatch,
operand: &V,
negated: bool,
nocase: bool,
) where
V: Carrier<sqlx::Postgres> + AsRef<str>,
{
let pattern = like_pattern(operand.as_ref(), kind);
not_wrapped(qb, negated, |qb| {
push_column(qb, at);
qb.push(if nocase { " ILIKE " } else { " LIKE " });
qb.push_bind(pattern);
qb.push(" ESCAPE '\\'");
});
}