From 1786a1457e261a0b384273946c84030cab770df4 Mon Sep 17 00:00:00 2001 From: Jon Harrell <4829245+jharrell@users.noreply.github.com> Date: Fri, 10 Jan 2025 13:39:30 -0600 Subject: [PATCH] fix transaction extension example --- .../300-client-extensions/120-query.mdx | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/content/200-orm/200-prisma-client/300-client-extensions/120-query.mdx b/content/200-orm/200-prisma-client/300-client-extensions/120-query.mdx index 72cbd01d7f..733c03041b 100644 --- a/content/200-orm/200-prisma-client/300-client-extensions/120-query.mdx +++ b/content/200-orm/200-prisma-client/300-client-extensions/120-query.mdx @@ -267,17 +267,20 @@ You can wrap your extended queries into a [batch transaction](/orm/prisma-client The following example extends `findFirst` so that it runs in a batch transaction. ```ts -const prisma = new PrismaClient().$extends({ - query: { - user: { - // Get the input `args` and a callback to `query` - async findFirst({ args, query, operation }) { - const [result] = await prisma.$transaction([query(args)]) // wrap the query in a batch transaction, and destructure the result to return an array - return result // return the first result found in the array +const transactionExtension = Prisma.defineExtension((prisma) => + prisma.$extends({ + query: { + user: { + // Get the input `args` and a callback to `query` + async findFirst({ args, query, operation }) { + const [result] = await prisma.$transaction([query(args)]) // wrap the query in a batch transaction, and destructure the result to return an array + return result // return the first result found in the array + }, }, }, - }, -}) + }) +) +const prisma = new PrismaClient().$extends(transactionExtension) ``` ## Query extensions versus middlewares