Skip to content

Commit

Permalink
feat(client): enable ITX support for DataProxy (#16005)
Browse files Browse the repository at this point in the history
Closes prisma/client-planning#92
Closes #16177

Co-authored-by: Daniel Starns <danielstarns@hotmail.com>
Co-authored-by: Sergey Tatarintsev <tatarintsev@prisma.io>
  • Loading branch information
3 people committed Nov 8, 2022
1 parent a34b236 commit 2785eaa
Show file tree
Hide file tree
Showing 33 changed files with 1,168 additions and 883 deletions.
2 changes: 1 addition & 1 deletion packages/client/package.json
Expand Up @@ -79,7 +79,7 @@
"@prisma/instrumentation": "workspace:*",
"@prisma/internals": "workspace:*",
"@prisma/migrate": "workspace:*",
"@prisma/mini-proxy": "0.2.0",
"@prisma/mini-proxy": "0.3.0",
"@swc-node/register": "1.5.4",
"@swc/core": "1.3.14",
"@swc/jest": "0.2.23",
Expand Down
9 changes: 6 additions & 3 deletions packages/client/src/runtime/RequestHandler.ts
Expand Up @@ -69,7 +69,7 @@ function getRequestInfo(request: Request) {
}

return {
batchTransaction: transaction?.kind === 'batch' ? transaction : undefined,
transaction,
headers,
}
}
Expand All @@ -92,13 +92,16 @@ export class RequestHandler {
// TODO: pass the child information to QE for it to issue links to queries
// const links = requests.map((r) => trace.getSpanContext(r.otelChildCtx!))

return this.client._engine.requestBatch(queries, info.headers, info.batchTransaction)
const batchTransaction = info.transaction?.kind === 'batch' ? info.transaction : undefined

return this.client._engine.requestBatch(queries, info.headers, batchTransaction)
},
singleLoader: (request) => {
const info = getRequestInfo(request)
const query = String(request.document)
const interactiveTransaction = info.transaction?.kind === 'itx' ? info.transaction : undefined

return this.client._engine.request(query, info.headers)
return this.client._engine.request(query, info.headers, interactiveTransaction)
},
batchBy: (request) => {
if (request.transaction?.id) {
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/runtime/core/request/PrismaPromise.ts
Expand Up @@ -9,6 +9,7 @@ export type PrismaPromiseBatchTransaction = {
export type PrismaPromiseInteractiveTransaction = {
kind: 'itx'
id: string
payload: unknown
}

export type PrismaPromiseTransaction = PrismaPromiseBatchTransaction | PrismaPromiseInteractiveTransaction
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/runtime/getPrismaClient.ts
Expand Up @@ -974,7 +974,7 @@ new PrismaClient({
let result: unknown
try {
// execute user logic with a proxied the client
result = await callback(transactionProxy(this, { id: info.id }))
result = await callback(transactionProxy(this, { id: info.id, payload: info.payload }))

// it went well, then we commit the transaction
await this._engine.transaction('commit', headers, info)
Expand Down
Expand Up @@ -13,8 +13,8 @@ exports[`interactive-transactions (provider=cockroachdb) batching rollback 1`] =
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0
XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
XX prisma.user.create(
Unique constraint failed on the fields: (\`email\`)
Expand All @@ -37,8 +37,8 @@ exports[`interactive-transactions (provider=mongodb) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0
XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
XX prisma.user.create(
Unique constraint failed on the constraint: \`User_email_key\`
Expand Down Expand Up @@ -69,8 +69,8 @@ exports[`interactive-transactions (provider=mysql) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0
XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
XX prisma.user.create(
Unique constraint failed on the constraint: \`User_email_key\`
Expand Down Expand Up @@ -101,8 +101,8 @@ exports[`interactive-transactions (provider=postgresql) batching rollback 1`] =
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0
XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
XX prisma.user.create(
Unique constraint failed on the fields: (\`email\`)
Expand Down Expand Up @@ -133,8 +133,8 @@ exports[`interactive-transactions (provider=sqlite) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0
XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
XX prisma.user.create(
Unique constraint failed on the fields: (\`email\`)
Expand Down Expand Up @@ -165,8 +165,8 @@ exports[`interactive-transactions (provider=sqlserver) batching rollback 1`] = `
Invalid \`prisma.user.create()\` invocation in
/client/tests/functional/interactive-transactions/tests.ts:0:0
XX */
XX testIf(getClientEngineType() === ClientEngineType.Library)('batching rollback', async () => {
XX 'batching rollback',
XX async () => {
XX const result = prisma.$transaction([
XX prisma.user.create(
Unique constraint failed on the constraint: \`dbo.User\`
Expand Down

0 comments on commit 2785eaa

Please sign in to comment.