-
Notifications
You must be signed in to change notification settings - Fork 860
Add case sensitive/insensitive querying #3611
Comments
I also encountered that need for an entity lookup feature. Adding this in would help a lot, as we need to have both sensitive and insensitive query options, which blocks the easy way out (DB collation). |
I have the same problem too. Django names this filter "icontains", e.g. |
I have the same issue here. |
I have hit the same issue myself for a project I'm starting, in which product names need to be searchable in a case insensitive fashion. Is there any sort of manual workaround in the meantime? |
Yes there are some hacks like using a string with all searchable information chained & lowercase. After doing that you have to lowercase the search query and use Don't forget to update the string while you are running mutations. |
Is there any hacky way to resolve this? If I tried to change my args in resolvers to uppercase or lowercase, it can be matched with first input letter, but no way after second letter input.
|
A work around I'm implementing right now is having a separate Index type for whatever you're going to be querying, and store the relevant data there lowercased. Then you can search with .toLowerCase() on your args. In my case, I have a Book type with author, title, isbn, description, etc. I have a BookIndex with the author, title, and isbn, author and title being case insensitive. I retrieve the ISBN from there and then search query for the actual data I want. E: If you want to see more on how I implemented the work-around, I wrote a blog post about it: https://bridgerputnam.me/blog/case-insensitive-search-with-prisma-using-indexes |
Hey @schickling, Has there been any progress on this or at least a recommended workaround? |
This is what I'm currently using const variables = {
where:{
OR: [
{name_contains: inputValue},
{name_contains: inputValue.toLowerCase()},
{name_contains: inputValue.toUpperCase()},
{name_contains: titleCase(inputValue)},
]
}
} export function titleCase(str: string):string {
let string = str.toLowerCase().split(' ');
for (var i = 0; i < string.length; i++) {
string[i] = string[i].charAt(0).toUpperCase() + string[i].slice(1);
}
return string.join(' ');
} |
@schickling Any updates on this? Kind of lacking when you compare to other ORMs that simulate "LIKE" statements in MySQL. |
That's a great point. Thanks a lot for pinging me @iRoachie. We'll make sure to consider this for the upcoming client API redesign in Prisma 2. |
I must added normalizeTitle as Prisma cannot perform case insensitive search. Source: prisma/prisma#3611
Ok, everybody here wrote that it doesn't support case insensitive search. My search is actually straightforward:
|
I would like to know how queries can be case insensitive. Any news on this? |
Doing a workaround at the moment by storing an extra variable for every param I'll expose to search. |
@iRoachie interestingly enough, I have decided to do the same with the index as suggested by @Putnam14. However, slightly different I think. I essentially create a relationship between Item and ItemIndex whilst exposing params like you said, like so:
In ItemIndex, I only store the { title } in lower case as well as the { item { id } }. Then I have written a Query which queries each Item based on the relationship of ItemIndex to Item using the id. I do so like this:
The query on the client side has all the params necessary, and returning the array with those params enables me to expose them all on the front end. Whether or not this is the most efficient way of doing things I do not know, but I'd like to know if you have any idea 😄 |
Case incensitive query is a critical feature
|
I've had to circumvent this by creating an additional field that my resolver copies and transforms to lowercase. I then do queries over that field utilizing a search parameter that is transformed to lowercase as well. This approach is a bit of a pain to maintain, and is error prone. It is possible to have stale data if you forget to update the extra field during mutations. Case insensitive querying would solve all of these issues. This feature is at the top of my wish list. Though, if we are going to dream about features... being able to to do something similar to SQL WHERE LIKE would open up so many doors. Though I understand that dealing with character encodings is a developers worst nightmare. Prisma was designed to be database agnostic. Doing complex string queries over a diverse set of character encodings may not have a solution. |
Hello everyone! |
facing same issue, any updates on this? |
We just had the same problem in our app that uses GraphQL with Apollo and Neo4j. We will be writing custom queries for our search queries to get around this. |
Any update on when this will be available? |
As mentioned before, it works correctly in demo servers with MySQL but doesn't in Postgres. @schickling Will this be considered as a bug to be fixed in Prisma v1 under maintenance mode? |
we had to all kinds of hacks (raw queries) to get this case sensitive search working. |
Sees this issue, dies internally Prisma is great and thanks for the hard work but this seems a very needed functionality 😢 |
not complaining, but we are thinking to get away from prisma as this needs a lot of hacks for our code. i wish there was a workaround. |
@schickling Do you have an update on this topic because the link you've provided to the API redesign for prisma 2 is not available anymore and this feature is still not implemented in prisma 2? |
Im using prisma with mongo connector. |
This feature is really needed. I don’t mind taking a stab and making a or for this if the Prisma team is willing |
Any idea on this ? Is it work now ? |
@williamkwao If you have a go at it, I'll help get it reviewed and merged |
It has been more than 1 year since this thread was created but I see no clear solution from Prisma... I have many things related to my items I need to search case-insensitively - Items with Category, User, ProgressRecords and its Tally ,etc. I am now trying to use rawAccess option (I am using Postgres for databse). However, I found that all the relationships are managed solely on mapping tables in database without any indexing in each object tables due to the prisma database structure. Also, I have to be very careful accessing my database directly for search as I have to consider SQL injection issue... |
As another similar option, Ben Awad has this youtube video explaining another solution to connect database directly. https://www.youtube.com/watch?time_continue=12&v=YUjlBuI8xsU&feature=emb_logo Update (20 Dec 2019): |
add it in prisma2 pls |
FYI @herbertpimentel opened an issue for the photon project of prisma 2. I think it would be great if everybody would upvote and follow/subscribe this one. |
Please add this into Prisma 1. I can't migrate to Prisma 2 yet as there are missing features that I am using. |
What is the best practice for this in 2021? |
@analoguezone To migrate to prisma 2 which now has this capability. |
Try mode
|
@svnshikhil This is an issue for Prisma 1 |
It worked for me. Thanks! |
Right now we are implementing a search field in our frontend but we noticed that it's not possible to have case insensitive queries. So everything you are typing in our search field has to be case sensitive. That's a big problem!
Solution
A solution would be to have a new field for the
where
attribute e.g. thename_contains
field should also havename_contains_case_insensitive
.Maybe there are better solutions but this was my first idea.
This problem was also noticed in #3301.
The text was updated successfully, but these errors were encountered: