Combine query mode with operators
I am trying to do a case insensitive search based on two different fields, however it doesn't seem to be working also can't find any docs on this. I tried the following but the search is still case sensitive:
db
.candidate()
.find_many(vec![or!(
and!(
candidate::name::mode(crate::prisma::_prisma::QueryMode::Insensitive),
candidate::name::contains(search.clone()),
),
and!(
candidate::email::mode(crate::prisma::_prisma::QueryMode::Insensitive),
candidate::email::contains(search.clone()),
)
)])
.take(query.limit)
.skip(query.offset)
.exec();
It works fine if I just do it against one field with out the ors and ands.
Thought I fixed this earlier but didn't apply it to and. Try using rev = "e44cae1e680e5b0a8f73f68fc99fc6c40066fb83".
The above code still does case sensitive search on rev = "e44cae1e680e5b0a8f73f68fc99fc6c40066fb83"
Did you use that version for both the CLI and library and then regenerate the client? I tried it with Postgres on my machine and it works fine.
I changed my Cargo.toml to:
prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "e44cae1e680e5b0a8f73f68fc99fc6c40066fb83" }
prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", rev = "e44cae1e680e5b0a8f73f68fc99fc6c40066fb83" }
then ran the generate command. My actual code looks like this in case it makes a difference:
pub async fn find(
Extension(db): Extension<Arc<PrismaClient>>,
Validated(Query(query)): Validated<Query<FindQuery>>,
) -> ApiResult<FindResponse> {
let mut params = vec![];
if let Some(search) = &query.search {
params.push(or!(
and!(
candidate::name::mode(crate::prisma::_prisma::QueryMode::Insensitive),
candidate::name::contains(search.clone()),
),
and!(
candidate::email::mode(crate::prisma::_prisma::QueryMode::Insensitive),
candidate::email::contains(search.clone()),
)
));
}
let candidates = db
.candidate()
.find_many(params.clone())
.take(query.limit)
.skip(query.offset)
.exec();
let count = db.candidate().count(params).exec();
let (candidates, count) = try_join!(candidates, count)?;
Ok(Json(FindResponse {
records: candidates,
query,
total_records: count,
}))
}
note that I clone the params vec.
My bad, I pointed you to the wrong commit. Try rev = "be9440002417fcbbe1a7ab2967d626577468f4c4".
Works, thanks!