Skip to content

Commit

Permalink
feat(client): orderBy for composite types (#12004)
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Mar 1, 2022
1 parent 7f0ad73 commit 39a7862
Show file tree
Hide file tree
Showing 30 changed files with 853 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -106,7 +106,7 @@ jobs:
# CLIENT (without types test)
#
client:
timeout-minutes: 25
timeout-minutes: 35
runs-on: ${{ matrix.os }}

needs: detect_jobs_to_run
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Expand Up @@ -67,9 +67,9 @@
"devDependencies": {
"@prisma/client": "workspace:*",
"@prisma/debug": "workspace:*",
"@prisma/fetch-engine": "3.11.0-11.5b3bbd566d0f91cb9f74187bfdb7c490a6a4e825",
"@prisma/fetch-engine": "3.11.0-12.9907684a5845cbb6a7aa712fa21fe75455b9b6f6",
"@prisma/generator-helper": "workspace:*",
"@prisma/get-platform": "3.11.0-11.5b3bbd566d0f91cb9f74187bfdb7c490a6a4e825",
"@prisma/get-platform": "3.11.0-12.9907684a5845cbb6a7aa712fa21fe75455b9b6f6",
"@prisma/migrate": "workspace:*",
"@prisma/sdk": "workspace:*",
"@prisma/studio": "0.458.0",
Expand Down Expand Up @@ -118,7 +118,7 @@
"preinstall": "node scripts/preinstall-entry.js"
},
"dependencies": {
"@prisma/engines": "3.11.0-11.5b3bbd566d0f91cb9f74187bfdb7c490a6a4e825"
"@prisma/engines": "3.11.0-12.9907684a5845cbb6a7aa712fa21fe75455b9b6f6"
},
"sideEffects": false
}
1 change: 1 addition & 0 deletions packages/client/.gitignore
Expand Up @@ -5,4 +5,5 @@

pnpm-lock.yaml
*.tsbuildinfo
junit.xml
.DS_Store
8 changes: 4 additions & 4 deletions packages/client/package.json
Expand Up @@ -63,10 +63,10 @@
"@opentelemetry/api": "1.0.3",
"@prisma/debug": "workspace:*",
"@prisma/engine-core": "workspace:*",
"@prisma/engines": "3.11.0-11.5b3bbd566d0f91cb9f74187bfdb7c490a6a4e825",
"@prisma/fetch-engine": "3.11.0-11.5b3bbd566d0f91cb9f74187bfdb7c490a6a4e825",
"@prisma/engines": "3.11.0-12.9907684a5845cbb6a7aa712fa21fe75455b9b6f6",
"@prisma/fetch-engine": "3.11.0-12.9907684a5845cbb6a7aa712fa21fe75455b9b6f6",
"@prisma/generator-helper": "workspace:*",
"@prisma/get-platform": "3.11.0-11.5b3bbd566d0f91cb9f74187bfdb7c490a6a4e825",
"@prisma/get-platform": "3.11.0-12.9907684a5845cbb6a7aa712fa21fe75455b9b6f6",
"@prisma/migrate": "workspace:*",
"@prisma/sdk": "workspace:*",
"@timsuchanek/copy": "1.4.5",
Expand Down Expand Up @@ -121,7 +121,7 @@
}
},
"dependencies": {
"@prisma/engines-version": "3.11.0-11.5b3bbd566d0f91cb9f74187bfdb7c490a6a4e825"
"@prisma/engines-version": "3.11.0-12.9907684a5845cbb6a7aa712fa21fe75455b9b6f6"
},
"sideEffects": false
}
@@ -0,0 +1,15 @@
export function commentOptionalPropDataA(id: string) {
return {
id: id,
country: 'France',
content: {
set: {
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
},
}
}
@@ -0,0 +1,19 @@
export function commentOptionalPropDataB(id: string) {
return {
id: id,
country: 'France',
content: {
text: 'Goodbye World',
upvotes: [
{
vote: false,
userId: '11',
},
{
vote: true,
userId: '12',
},
],
},
}
}
@@ -0,0 +1,15 @@
export function commentRequiredListDataA(id: string) {
return {
id: id,
country: 'France',
contents: {
set: {
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
},
}
}
@@ -0,0 +1,24 @@
export function commentRequiredListDataB(id: string) {
return {
id: id,
country: 'France',
contents: {
set: [
{
text: 'Goodbye World',
upvotes: {
vote: false,
userId: '11',
},
},
{
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
],
},
}
}
@@ -0,0 +1,15 @@
export function commentRequiredPropDataA(id: string) {
return {
id: id,
country: 'France',
content: {
set: {
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
},
}
}
@@ -0,0 +1,19 @@
export function commentRequiredPropDataB(id: string) {
return {
id: id,
country: 'France',
content: {
text: 'Goodbye World',
upvotes: [
{
vote: false,
userId: '11',
},
{
vote: true,
userId: '12',
},
],
},
}
}
@@ -0,0 +1,61 @@
import { getTestClient } from '../../../../../utils/getTestClient'

const describeIf = (condition: boolean) => (condition ? describe : describe.skip)

let PrismaClient, prisma

const id = '6ccccccccccccccccccccccc'

/**
* Test aggregate operations on list composite fields
*/
describeIf(!process.env.TEST_SKIP_MONGODB)('aggregate > list', () => {
beforeAll(async () => {
PrismaClient = await getTestClient('../')
prisma = new PrismaClient()
})

beforeEach(async () => {
await prisma.commentRequiredList.deleteMany({ where: { id } })
await prisma.commentRequiredList.create({
data: {
id,
country: 'France',
contents: {
set: {
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
},
},
})
})

afterEach(async () => {
await prisma.$disconnect()
})

/**
* Simple aggregate
*/
test('simple', async () => {
const comment = await prisma.commentRequiredList.aggregate({
where: { id },
orderBy: {
contents: {
_count: 'asc',
},
},
_count: true,
})

expect(comment).toMatchInlineSnapshot(`
Object {
_count: 1,
}
`)
})
})
@@ -0,0 +1,63 @@
import { getTestClient } from '../../../../../utils/getTestClient'

const describeIf = (condition: boolean) => (condition ? describe : describe.skip)

let PrismaClient, prisma

const id = '4ccccccccccccccccccccccc'

/**
* Test aggregate operations on optional composite fields
*/
describeIf(!process.env.TEST_SKIP_MONGODB)('aggregate > optional', () => {
beforeAll(async () => {
PrismaClient = await getTestClient('../')
prisma = new PrismaClient()
})

beforeEach(async () => {
await prisma.commentOptionalProp.deleteMany({ where: { id } })
await prisma.commentOptionalProp.create({
data: {
id,
country: 'France',
content: {
set: {
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
},
},
})
})

afterEach(async () => {
await prisma.$disconnect()
})

/**
* Simple aggregate
*/
test('aggregate', async () => {
const comment = await prisma.commentOptionalProp.aggregate({
where: { id },
orderBy: {
content: {
upvotes: {
_count: 'desc',
},
},
},
_count: true,
})

expect(comment).toMatchInlineSnapshot(`
Object {
_count: 1,
}
`)
})
})
@@ -0,0 +1,63 @@
import { getTestClient } from '../../../../../utils/getTestClient'

const describeIf = (condition: boolean) => (condition ? describe : describe.skip)

let PrismaClient, prisma

const id = '5ccccccccccccccccccccccc'

/**
* Test aggregate operations on required composite fields
*/
describeIf(!process.env.TEST_SKIP_MONGODB)('aggregate > required', () => {
beforeAll(async () => {
PrismaClient = await getTestClient('../')
prisma = new PrismaClient()
})

beforeEach(async () => {
await prisma.commentRequiredProp.deleteMany({ where: { id } })
await prisma.commentRequiredProp.create({
data: {
id,
country: 'France',
content: {
set: {
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
},
},
})
})

afterEach(async () => {
await prisma.$disconnect()
})

/**
* Simple aggregate
*/
test('aggregate', async () => {
const comment = await prisma.commentRequiredProp.aggregate({
where: { id },
orderBy: {
content: {
upvotes: {
_count: 'desc',
},
},
},
_count: true,
})

expect(comment).toMatchInlineSnapshot(`
Object {
_count: 1,
}
`)
})
})

0 comments on commit 39a7862

Please sign in to comment.