Skip to content

Commit

Permalink
fix(client): aggregate lowercase model
Browse files Browse the repository at this point in the history
Closes #772
  • Loading branch information
timsuchanek committed Jul 13, 2020
1 parent 539db28 commit f7449f2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ module.exports = async () => {
const prisma = new PrismaClient()

const result = await prisma.user.aggregate({
where: {
age: {
gt: -1,
},
},
skip: 0,
take: 10000,
avg: {
age: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ generator client {
}

// / User model comment
model User {
model user {
id String @default(uuid()) @id
email String @unique
age Int
Expand All @@ -29,7 +29,7 @@ model Post {
title String
content String?
authorId String?
author User? @relation(fields: [authorId], references: [id])
author user? @relation(fields: [authorId], references: [id])
Like Like[]
}

Expand All @@ -52,7 +52,7 @@ model MachineData {
model Like {
id String @default(cuid()) @id
userId String
user User @relation(fields: [userId], references: [id])
user user @relation(fields: [userId], references: [id])
postId String
post Post @relation(fields: [postId], references: [id])
Expand Down
7 changes: 7 additions & 0 deletions src/packages/client/src/generation/TSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,13 @@ export class Model implements Generatable {
private getAggregationTypes() {
const { model, mapping } = this
const aggregateType = this.dmmf.outputTypeMap[getAggregateName(model.name)]
if (!aggregateType) {
throw new Error(
`Could not get aggregate type "${getAggregateName(model.name)}" for "${
model.name
}"`,
)
}
const aggregateTypes = [aggregateType]

const avgType = this.dmmf.outputTypeMap[getAvgAggregateName(model.name)]
Expand Down
10 changes: 5 additions & 5 deletions src/packages/client/src/generation/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ export function getSelectName(modelName: string): string {
}

export function getAggregateName(modelName: string): string {
return `Aggregate${modelName}`
return `Aggregate${capitalize(modelName)}`
}

export function getAvgAggregateName(modelName: string): string {
return `${modelName}AvgAggregateOutputType`
return `${capitalize(modelName)}AvgAggregateOutputType`
}

export function getSumAggregateName(modelName: string): string {
return `${modelName}SumAggregateOutputType`
return `${capitalize(modelName)}SumAggregateOutputType`
}

export function getMinAggregateName(modelName: string): string {
return `${modelName}MinAggregateOutputType`
return `${capitalize(modelName)}MinAggregateOutputType`
}

export function getMaxAggregateName(modelName: string): string {
return `${modelName}MaxAggregateOutputType`
return `${capitalize(modelName)}MaxAggregateOutputType`
}

export function getAggregateInputType(aggregateOutputType: string): string {
Expand Down

0 comments on commit f7449f2

Please sign in to comment.