Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Module

$extends

Prisma Client’s $extends method creates a new extended client with custom model, client, result, or query behavior. Extensions can be supplied inline or defined separately and then attached.

How it works

$extends takes an extension definition or a defined extension and returns a new Prisma Client variant. The definition can add model, client, result, or query behavior; the returned client carries those additions while the original client remains available.

Syntax

const extendedPrisma = prisma.$extends(extension);

Parameters

NameTypeDescription
extensionPrisma.ExtensionAn extension object containing one or more supported components: model, client, result, or query; a reusable extension created with Prisma.defineExtension can also be passed.

Returns

A new extended Prisma Client variant wrapped by the supplied extension or extensions.

Key points

  • $extends supports four extension areas: model methods, client methods, result fields or methods, and query behavior.
  • An extension can be supplied directly to $extends, or created with Prisma.defineExtension and then supplied to $extends.
  • A single extension can be attached by itself, while multiple extensions can also be combined on an extended client.

Common mistakes

  • The value returned by $extends is a separate extended client, so code using the original client does not automatically receive the added behavior.
  • Put customization under the component matching its scope; $extends itself does not imply a particular kind of extension.

Example: Add a model method with $extends

import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient().$extends({
  name: "userHelpers",
  model: {
    user: {
      async findByEmail(email: string) {
        return this.findUnique({ where: { email } });
      },
    },
  },
});

const user = await prisma.user.findByEmail("ada@example.com");
console.log(user);

Creates an extended Prisma Client with a type-safe method on the User model.

When to use it

Model helpers

Add domain-specific operations to a model delegate.

Client methods

Expose cross-model or application-wide operations on the client.

Result customization

Add computed fields or methods to returned records.

Query extensions

Inspect or modify Prisma query behavior.

Interview questions

QWhat does Prisma Client $extends do?

$extends creates an extended Prisma Client from an existing client. The extension can contain model, client, result, or query components, and the returned client exposes the added behavior.

Follow-up: How can several extensions be combined? Chain $extends calls or associate multiple extensions with one extended client.

QHow do you add a custom model method?

A model extension adds methods to one or more Prisma models. For example, a method can wrap an existing model operation and be called through the extended model delegate.

Follow-up: How would you target every model? Use the model extension's $allModels structure rather than repeating the method for each model.

QWhen should a client-level extension be used?

Client-level extensions add methods directly to the Prisma Client object rather than to a model delegate. They are useful for operations that do not belong to one particular model.

Follow-up: How can a reusable extension be organized? Define it with Prisma.defineExtension, then pass the resulting extension to the client-level $extends method.

  • Prisma.defineExtension
  • model
  • client
  • result
  • query
  • $allModels

Source: Client Extensions - Prisma Documentation. Checked 2026-10-16.