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