Prisma-client-js: Filter based on the count of items of a relation

Created on 15 Jan 2020  路  4Comments  路  Source: prisma/prisma-client-js

Problem:

We have a large number of users, we would like to filter only the users that have 3 or more posts with type blog

Possible solution

Add an extension to the existing PostFilter to take into account how many items of the relation there are and use an intFilter to match certain requirements

The the none and every field might be overkill for this, since the count of the amount of items that not match a requirement does not make a lot of sense but probably someone will find a use for it :-)

Dream API spec:

export declare type CountPostFilter= {
    count: IntFilter,
    where?: PostFilter,
};

export declare type PostFilter = {
    every?: PostWhereInput | null;
    some?: PostWhereInput | null;
    none?: PostWhereInput | null;
}

Example queries:

All users with more than 10 posts

users(where: {
    posts: {
        count: { gt: 10 },
     },
}): 

All users with more than or equal 4 posts with type 'blog'

users(where: {
    posts: {
        count: { gte: 4 },
        where: { some: { type: {equals: "blog"} },
     },
}): 

All users with only posts with type 'blog' and at least 5 posts

users(where: {
    posts: {
        count: { gte: 5 },
        where: { every: { type: {equals: "blog"} },
     },
}): 

All users that have no posts with type 'blog' but have 10 posts with another type

users(where: {
    posts: {
        count: { gte: 10 },
        where: { none : { type: {equals: "blog"} },
     },
}): 
kinfeature teaclient

Most helpful comment

@maartenraes We're actually implementing this one right now! Unfortunately, I can't give an ETA since there's still some unknowns to work through, but group by support is one of our top priorities.

All 4 comments

This will be solved by #1 馃檪

Any ETA on implementation of #1 ? Seems in design right now, but I don't know how long it takes from design to implementation to beta to release :-)

@maartenraes We're actually implementing this one right now! Unfortunately, I can't give an ETA since there's still some unknowns to work through, but group by support is one of our top priorities.

1 is now released in 2.14. I am going to close this one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vergil333 picture Vergil333  路  3Comments

williamluke4 picture williamluke4  路  3Comments

janpio picture janpio  路  4Comments

divyenduz picture divyenduz  路  3Comments

FluorescentHallucinogen picture FluorescentHallucinogen  路  3Comments