Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(adapter-d1): use changes instead of rows_written #24083

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/adapter-d1/src/d1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class D1Queryable<ClientT extends StdClient> implements Queryable {
debug(`${tag} %O`, query)

const res = await this.performIO(query, true)
return res.map((result) => (result as D1Response).meta.rows_written ?? 0)
return res.map((result) => (result as D1Response).meta.changes ?? 0)
}

private async performIO(query: Query, executeRaw = false): Promise<Result<PerformIOResult>> {
Expand Down
4 changes: 4 additions & 0 deletions packages/client/tests/functional/issues/23902/_matrix.ts
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])
37 changes: 37 additions & 0 deletions packages/client/tests/functional/issues/23902/prisma/_schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { idForProvider } from '../../../_utils/idForProvider'
import testMatrix from '../_matrix'

export default testMatrix.setupSchema(({ provider }) => {
return /* Prisma */ `
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "${provider}"
url = env("DATABASE_URI_${provider}")
}

model User {
id ${idForProvider(provider)}
email String @unique
name String?
posts Post[]
}

model Post {
id ${idForProvider(provider)}
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
content String?
published Boolean @default(false)
viewCount Int @default(0)
author User? @relation(fields: [authorId], references: [id])
authorId String?

// This is the most important part of the test
@@index([authorId])
}
`
})
45 changes: 45 additions & 0 deletions packages/client/tests/functional/issues/23902/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import testMatrix from './_matrix'
// @ts-ignore
import type { PrismaClient } from './node_modules/@prisma/client'

declare let prisma: PrismaClient

// https://github.com/prisma/prisma/issues/4004
testMatrix.setupTestSuite(() => {
test('should not throw error when updating fields on a many to many join table', async () => {
const post = await prisma.post.create({
data: {
title: 'Hello World',
},
})

expect(post).toMatchObject({
authorId: null,
content: null,
createdAt: expect.any(Date),
id: expect.any(String),
published: false,
title: 'Hello World',
updatedAt: expect.any(Date),
viewCount: 0,
})

await expect(
prisma.user.create({
data: {
email: 'test@example.com',
name: 'Test',
posts: {
connect: {
id: post.id,
},
},
},
}),
).resolves.toMatchObject({
email: 'test@example.com',
id: expect.any(String),
name: 'Test',
})
})
})