RobertCraigie / prisma-client-py

Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
https://prisma-client-py.readthedocs.io
Apache License 2.0
1.83k stars 77 forks source link

Add support for including count of relational fields #26

Open RobertCraigie opened 3 years ago

RobertCraigie commented 3 years ago

Problem

Prisma supports including the count of a relational field, so we should too.

const users = await prisma.user.findMany({
  include: {
    _count: {
      select: { posts: true },
    },
  },
})

which returns an object like this

{
  id: 1,
  email: 'alice@prisma.io',
  name: 'Alice',
  _count: { posts: 2 }
}

Prisma also have support for filtering by the count of the relation, see https://www.prisma.io/docs/concepts/components/prisma-client/aggregation-grouping-summarizing#filter-the-relation-count

rxsine commented 1 month ago

This feature is needed.