Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine query mode with operators #175

Closed
affanshahid opened this issue Oct 14, 2022 · 6 comments · Fixed by #179
Closed

Combine query mode with operators #175

affanshahid opened this issue Oct 14, 2022 · 6 comments · Fixed by #179
Labels
bug Something isn't working lib

Comments

@affanshahid
Copy link
Contributor

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.

@Brendonovich Brendonovich added bug Something isn't working lib labels Oct 15, 2022
@Brendonovich Brendonovich added this to the 0.6.3 milestone Oct 15, 2022
@Brendonovich
Copy link
Owner

Thought I fixed this earlier but didn't apply it to and. Try using rev = "e44cae1e680e5b0a8f73f68fc99fc6c40066fb83".

@affanshahid
Copy link
Contributor Author

The above code still does case sensitive search on rev = "e44cae1e680e5b0a8f73f68fc99fc6c40066fb83"

@Brendonovich
Copy link
Owner

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.

@affanshahid
Copy link
Contributor Author

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.

@Brendonovich
Copy link
Owner

My bad, I pointed you to the wrong commit. Try rev = "be9440002417fcbbe1a7ab2967d626577468f4c4".

@affanshahid
Copy link
Contributor Author

Works, thanks!

@Brendonovich Brendonovich linked a pull request Oct 19, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lib
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants