use quokka::helper::database::{Bindable, SearchCriteria};
use sqlx::QueryBuilder;
pub struct ILikeCriteria {
pub column: &'static str,
pub value: Box<dyn Bindable<sqlx::Postgres>>,
}
impl ILikeCriteria {
pub fn new(column: &'static str, value: impl Bindable<sqlx::Postgres> + 'static) -> Self {
Self {
column,
value: Box::new(value),
}
}
}
impl SearchCriteria for ILikeCriteria {
fn extend_query_builder(&self, qb: &mut QueryBuilder<'_, sqlx::Postgres>) {
qb.push("LOWER(")
.push(self.column)
.push(")")
.push(" LIKE LOWER(");
self.value.bind_to_query_builder(qb);
qb.push(")");
}
}