-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(adapter-d1): set maxBindValues: 100 (#24242)
* feat(adapter-d1): set maxBindValues: 100 * add 2 tests * fix test and lint * Fix Property 'toBeObject' does not exist * also replace toBeArrayOfSize --------- Co-authored-by: Joël Galeran <Jolg42@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineMatrix } from '../_utils/defineMatrix' | ||
import { allProviders } from '../_utils/providers' | ||
|
||
export default defineMatrix(() => [allProviders]) |
33 changes: 33 additions & 0 deletions
33
packages/client/tests/functional/max_bind_value/prisma/_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { idForProvider } from '../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
const id = idForProvider(provider) | ||
|
||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model User { | ||
id ${id} | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
} | ||
model Post { | ||
id ${id} | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
author User? @relation(fields: [authorId], references: [id]) | ||
authorId String? | ||
} | ||
` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { Post, PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
|
||
testMatrix.setupTestSuite(() => { | ||
const posts: Pick<Post, 'id'>[] = [] | ||
const numberOfUsers = 200 | ||
|
||
beforeAll(async () => { | ||
// Create x users with 2 posts each | ||
for (let i = 0; i < numberOfUsers; i++) { | ||
await prisma.user.create({ | ||
data: { | ||
email: `user${i}@example.com`, | ||
name: `User ${i}`, | ||
posts: { | ||
createMany: { | ||
data: [ | ||
{ | ||
title: `Post ${i}a`, | ||
content: `This is the content of the first post ${i}a by User ${i}`, | ||
}, | ||
{ | ||
title: `Post ${i}b`, | ||
content: `This is the content of the second post ${i}b by User ${i}`, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
posts.push(...(await prisma.post.findMany({ select: { id: true } }))) | ||
}) | ||
|
||
// It used to error on D1 with | ||
// Error in performIO: Error: D1_ERROR: too many SQL variables at offset 395 | ||
// see https://github.com/prisma/prisma/issues/23743 | ||
test('findMany() with more than 98 users with nested include should succeed', async () => { | ||
await expect( | ||
prisma.user.findMany({ | ||
include: { | ||
posts: true, | ||
}, | ||
}), | ||
).resolves.toHaveLength(numberOfUsers) | ||
}) | ||
|
||
// It used to error on D1 with | ||
// Error in performIO: Error: D1_ERROR: Expression tree is too large (maximum depth 100) | ||
// see https://github.com/prisma/prisma/issues/23919 | ||
test('create user with nested connect with more than 98 posts should succeed', async () => { | ||
await expect( | ||
prisma.user.create({ | ||
data: { | ||
name: 'Foo', | ||
email: 'foo@bar.org', | ||
posts: { | ||
connect: posts.map((it) => ({ id: it.id })), | ||
}, | ||
}, | ||
include: { | ||
posts: true, | ||
}, | ||
}), | ||
).resolves.toMatchObject({ | ||
id: expect.any(String), | ||
// ... | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters