This repository was archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
Group By #1
Copy link
Copy link
Closed
Labels
kind/featureA request for a new feature.A request for a new feature.roadmap/plannedPlanned for being picked up once we're done with the WIPPlanned for being picked up once we're done with the WIP
Milestone
Description
Problem
Most database support ways to indicate how to group results, especially in combination with usage of aggregators.
Prisma 2 currently doesn't offer any way to group results, and requires to fall back to using raw SQL queries. This defeats the benefits of having a type-safe client, and hurts code maintainability.
Suggested solution
Add support for ways to group results
Initial API example proposal:
type DynamicResult4 = {
lastName: string
records: User[]
aggregate: { age: { avg: number } }
}
const groupByResult: DynamicResult4 = await prisma.users.groupBy({
key: 'lastName',
having: { age: { avgGt: 10 } },
where: { isActive: true },
first: 100,
orderBy: { lastName: 'ASC' },
select: {
records: { take: 100 },
aggregate: { age: { avg: true } },
},
})
type DynamicResult5 = {
raw: any
records: User[]
aggregate: { age: { avg: number } }
}
const groupByResult2: DynamicResult5 = await prisma.users.groupBy({
raw: { key: 'firstName || lastName', having: 'AVG(age) > 50' },
select: {
records: { $first: 100 },
aggregate: { age: { avg: true } },
},
})Next steps
- Define scope of the kinds of group by statement we want to support first
- Agree on API design
- Implement in engines
- Implement in client
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind/featureA request for a new feature.A request for a new feature.roadmap/plannedPlanned for being picked up once we're done with the WIPPlanned for being picked up once we're done with the WIP