How to match against a text in an case-insensitive way in v2? #2771
-
|
Everything is in the title. I want to be able to do this: I have this: Condition::all().add(Column::Name.contains("joe"));And I see that there is this: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
This is the current workaround |
Beta Was this translation helpful? Give feedback.
-
|
It's something I use quite a bit, so I created an extension (because why not): use sea_orm::{prelude::*, sea_query::extension::postgres::PgExpr};
pub trait ColumnExt {
fn icontains(&self, s: &str) -> Expr;
}
impl<T> ColumnExt for T
where
T: ColumnTrait,
{
fn icontains(&self, s: &str) -> Expr {
self.into_expr().ilike(format!("%{}%", s.trim()))
}
}sea_orm::Condition::all()
.add_option(self.id.map(|id| Column::Id.eq(id)))
.add_option(self.email.map(|email| Column::Email.icontains(&email)))
.add_option(self.name.map(|name| Column::Name.icontains(&name))) |
Beta Was this translation helpful? Give feedback.
This is the current workaround
Column::Name.into_expr().ilike("%joe%")