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

How make to work OR Where request ? #55

Open
Kiborgik opened this issue Jun 20, 2023 · 6 comments
Open

How make to work OR Where request ? #55

Kiborgik opened this issue Jun 20, 2023 · 6 comments

Comments

@Kiborgik
Copy link

I tried a lot of different variatns, I simply want: SELECT * FROM "User" WHERE "fullName" LIKE '%RD%' OR "initials" LIKE '%RD%' OR "email" LIKE '%RD%'
this doesnt work { "$or":[ {"fullName":{"$cont":"RD"}}, {"initials":{"$cont":"RD"}}, {"email":{"$cont":"RD"}} ] } or put "$or": with [] or {} in any combinations

@Kiborgik
Copy link
Author

Kiborgik commented Jun 20, 2023

{ "$or": { "fullName":{ "$cont":"${searching}" }, "email":{ "$cont":"${searching}" } } } generating Query: SELECT "public"."User"."id", "public"."User"."fullName", "public"."User"."initials", "public"."User"."email", "public"."User"."password", "public"."User"."phone", "public"."User"."address", "public"."User"."comment", "public"."User"."role", "public"."User"."isActive", "public"."User"."createdAt", "public"."User"."updatedAt", "public"."User"."clientId" FROM "public"."User" WHERE ("public"."User"."fullName"::text LIKE $1 AND "public"."User"."email"::text LIKE $2) OFFSET $3 Params: ["%RB%","%RB%",0]
Why AND not OR?

@Kiborgik
Copy link
Author

@premieroctet man you did a great job, but is this project alive?

@simonKristensen
Copy link

Did you find a workaround for this? I'm having the same exact issue

@Kiborgik
Copy link
Author

Did you find a workaround for this? I'm having the same exact issue

write prisma code for cases like this and step by step remove this lib

@foyarash
Copy link
Contributor

Hello @Kiborgik sorry for the delay.

I think you're trying to use the $or operator in an invalid way.

Your $or request should be like {"$or": { "fullname": { "$cont": "RD }, "initials": { "$cont": "RD" }, "email": { "$cont": "RD" } } }

@ebuzzz
Copy link

ebuzzz commented Apr 5, 2024

There is still something strange going on in the parsing. I have this example (in JSON, but it's based on the where-query):

{
    "$and": {
        "archived": {
            "$eq": false
        },
        "$or": {
            "title": {
                "$cont": "aud"
            }
        },
        "uploaded_by": {
            "$eq": 3
        },
        "upload_timestamp": {
            "$gte": 1680678906
        }
    }
}

The parsePrismaWhere method parses this as:

{
  AND: {
    archived: { equals: false },
    uploaded_by: { equals: 3 },
    upload_timestamp: { gte: 1680678906 }
  }
}

The OR is removed completely. But adding an OR to an AND seems to be a normal use-case?

On further inspection, the issue seems to be in parseObjectCombination. Values of the processed objects are not checked for deeper objects. So the parsing is not recursive. I'm not sure why this method exists? Isn't it more logical to replace the calls to this function with parsePrismaWhere?

Never mind, this seems to be a limitation of Prisma itself. I can't find an example where AND and OR are nested. It seems that both can only be at the top level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants