-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Support nested where clauses #89
Comments
If it's easier, the library could support non-recursive queries first, and add recursive functionality later? So these queries would be supported: // Supported currently
const users = db.user.findMany({
where: {
name: {
equals: "something",
},
},
});
// NEW: single layer disjunction (OR)
const users = db.user.findMany({
where: {
OR: [
{
name: {
equals: "something",
},
},
{
email: {
contains: "@example.com",
},
},
],
},
});
// NEW: single layer conjunction (AND)
const users = db.user.findMany({
where: {
AND: [
{
name: {
equals: "something",
},
},
{
email: {
contains: "@example.com",
},
},
],
},
}); |
Hey, @camchenry. That's a good proposal. I believe your recursive const users = await prisma.user.findMany({
where: {
OR: [
{
name: {
startsWith: 'E',
},
},
{
- AND: {
+ AND: [{
profileViews: {
gt: 0,
},
role: {
equals: 'ADMIN',
},
},
- },
+ }],
],
},
}) If I understand that API correctly, both
|
Please, would you be interested in lending us a hand once more? I think the barebone for this feature would be to extend the data/src/query/compileQuery.ts Line 28 in 154d5b5
We can separate the regular |
@kettanaito I'm actually not sure about the missing braces, I took these examples from the Prisma docs, and there's a few examples where they don't have any brackets. I'm not familiar enough with the difference, but I think if it makes things easier for us to implement, we should just stick to explicit braces for the time being. I can try to dive into this later, I'm working through adding some more mock APIs in my company's main product, which is how this came up. We have a custom syntax for doing query filtering that looks like |
As mentioned in readme, the query API is inspired by Prisma and I believe that would be a good choice to extend it in the same way how Prisma is handling queries (Nevertheless, starting first with some simple cases and extending it further is cool idea!). I've used Prisma a little bit lately, but haven't managed to utilise the If it comes to the example provided in the issue description, I believe it's a valid syntax in Prisma. If I understood it correctly the const users = await prisma.user.findMany({
where: {
AND: [
{ // 1st condition
profileViews: {
gt: 0,
},
},
{ // 2nd condition
role: {
equals: "ADMIN",
},
},
],
},
}); or an object with keys, that each keys is some condition const users = await prisma.user.findMany({
where: {
AND: {
profileViews: { // 1st condition
gt: 0,
},
role: { // 2nd condition
equals: "ADMIN",
},
},
},
}); or as mentioned in https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#get-all-post-records-where-the-content-field-contains-prisma-and-published-is-false-no-and the const users = await prisma.user.findMany({
where: {
profileViews: { // 1st condition
gt: 0,
},
role: { // 2nd condition
equals: "ADMIN",
},
},
}); If I got it correctly, all the examples should return the same result, however I'm not an experienced Prisma user and it would be worth it to verify that behaviour - querying admins with at least 1 profile view. Similarly the const users = await prisma.user.findMany({
where: {
OR: {
key1: {
equals: "value1",
},
key2: {
equals: "value2",
},
}
},
}); However if someone would like to define condition like const users = await prisma.user.findMany({
where: {
OR: [
{
key1: {
equals: "value1",
},
},
{
key1: {
equals: "value2",
},
},
],
},
}); As mentioned before, I'm not 100% sure if that's the way how it's handled by Prisma, but that's how I understood it after reading the docs. I'll try to verify that assumption on a side project I'm working on, which is using Prisma and share results here 😉 EDIT:
|
Thanks for investigating this, @roertbb! I'm all hands for adopting |
wouldn't it be easier to use the graphql parser? https://dgraph.io/docs/graphql/queries/and-or-not/ |
@kettanaito Any news regarding this? Right now in the project where this would be crucial (doing query search over few different fields). |
Hey, @JasieBasie. This will be supported in the next version of this library, I'm currently testing this very functionality. The next version is unlikely to be released this year. |
It would be nice to support nested conjunctions/disjunctions (AND/OR) for creating complex where clause queries.
Example from the Prisma docs:
Haven't looked into implementing this, but would probably require checking for a special property like
AND
orOR
and handling the property accordingly.The text was updated successfully, but these errors were encountered: