Skip to content

Commit

Permalink
feat(client): aggregate runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jul 3, 2020
1 parent 3d5e41a commit fdd0b20
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 29 deletions.
32 changes: 17 additions & 15 deletions src/packages/client/fixtures/blog/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ const prisma = new PrismaClient({
})

async function main() {
const result = await prisma.user.aggregate({
avg: {
age: true,
blub: true,
},
sum: {
age: true,
},
min: {
age: true,
},
max: {
age: true,
},
count: true,
// const result = await prisma.user.aggregate({
// avg: {
// age3: true,
// },
// sum: {
// age: true,
// },
// min: {
// age: true,
// },
// max: {
// age: true,
// },
// count: true,
// })
const result = await prisma.user.count({
take: 10,
})
console.log(result)
prisma.disconnect()
Expand Down
4 changes: 0 additions & 4 deletions src/packages/client/src/__tests__/json-dmmf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ test('JsonFilter should contain equals and not', async () => {
"name": "id",
},
],
"isOneOf": true,
"name": "UserWhereUniqueInput",
},
Object {
Expand Down Expand Up @@ -157,7 +156,6 @@ test('JsonFilter should contain equals and not', async () => {
"name": "field",
},
],
"isOneOf": false,
"name": "UserCreateInput",
},
Object {
Expand Down Expand Up @@ -187,7 +185,6 @@ test('JsonFilter should contain equals and not', async () => {
"name": "field",
},
],
"isOneOf": false,
"name": "UserUpdateInput",
},
Object {
Expand Down Expand Up @@ -217,7 +214,6 @@ test('JsonFilter should contain equals and not', async () => {
"name": "field",
},
],
"isOneOf": false,
"name": "UserUpdateManyMutationInput",
},
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ module.exports = async () => {

await prisma.user.findMany()
prisma.disconnect()

// flakyness :shrug:
await new Promise((r) => setTimeout(r, 200))
assert(requests.length === 2)

const count = await prisma.user.count()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ datasource db {
}

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
experimentalFeatures = ["aggregations"]
}

// / User model comment
Expand All @@ -26,4 +27,4 @@ model Post {
content String?
authorId String?
author User? @relation(fields: [authorId], references: [id])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const del = promisify(rimraf)

jest.setTimeout(35000)

// TODO: Figure out the problem with debug

process.setMaxListeners(100)

let subDirs = getSubDirs(__dirname)
Expand All @@ -23,7 +21,7 @@ if (
) {
const dirsLeft = subDirs.filter((dir) => dir.includes(folderFilter))
if (dirsLeft.length > 0) {
subDirs = dirsLeft
subDirs = [dirsLeft[0]] // only take the first matchh
console.log(
`As ${folderFilter} is provided, only ${subDirs.join(
', ',
Expand Down
3 changes: 1 addition & 2 deletions src/packages/client/src/runtime/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ ${indent(this.children.map(String).join('\n'), tab)}
const fieldType = fieldError.error.field.outputType
.type as DMMF.OutputType

console.log(fieldError)

fieldType.fields
.filter((field) =>
fieldError.error.type === 'emptyInclude'
Expand Down Expand Up @@ -240,6 +238,7 @@ ${fieldErrors
callsite,
originalMethod: originalMethod || queryName,
showColors: errorFormat && errorFormat === 'pretty',
isValidationError: true,
})

let printJsonArgs: PrintJsonWithErrorsArgs = {
Expand Down
6 changes: 4 additions & 2 deletions src/packages/client/src/runtime/utils/printStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ function renderN(n: number, max: number): string {
export interface ErrorArgs {
callsite?: string
originalMethod: string
onUs?: boolean // is this on us?
onUs?: boolean // is this on us or is it a user error?
showColors?: boolean
renderPathRelative?: boolean
printFullStack?: boolean
isValidationError?: boolean
}

export interface PrintStackResult {
Expand All @@ -36,6 +37,7 @@ export const printStack = ({
showColors,
renderPathRelative,
printFullStack,
isValidationError,
}: ErrorArgs): PrintStackResult => {
const lastErrorHeight = 20
let callsiteStr = ':'
Expand Down Expand Up @@ -133,7 +135,7 @@ export const printStack = ({
: chalk.dim(' ' + l),
)
.join('\n')
if (!match) {
if (!match && !isValidationError) {
prevLines += '\n\n'
}
afterLines = ')'
Expand Down
2 changes: 1 addition & 1 deletion src/packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"scripts"
],
"prisma": {
"version": "ea035543e59571161e00ccd4063f5638283bfba7"
"version": "cbf44d96ec1c1a6584e0a1be9463b8bf65d12b0d"
},
"devDependencies": {
"@types/jest": "25.2.3",
Expand Down

0 comments on commit fdd0b20

Please sign in to comment.