> For the complete documentation index, see [llms.txt](https://transactional.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://transactional.gitbook.io/documentation/clients/prisma.md).

# Prisma

You can use Transactional with Prisma client to run your queries in a transaction, this requires [interactive transactions](https://www.prisma.io/docs/concepts/components/prisma-client/transactions#interactive-transactions) to be supported by the client.

## Install

```bash
npm install @transactional/core @transactional/prisma
```

## Usage

```typescript
import { prismaTransactional } from "@transactional/prisma";

const prisma = new PrismaClient().$extends(prismaTransactional);
```

{% hint style="info" %}
Prisma transactional extensions run queries using the unextended client, so make sure to use the transactional extension after other extensions, like logging extensions or extensions that add methods to the client.
{% endhint %}

### Using `@Transactional` Decorator

```typescript
import { Transactional } from "@transactional/core"

class Service {
    
    @Transactional()
    findCats() {
        // now all your prisma queries are run inside the same transaction.
        await prisma.cat.findMany({});
        await prisma.cat.findFirst({});
        ...
    }
}
```

### Using `transactional` Method

```typescript
import { transactional } from "@transactional/core"

const findCats = transactional(() => {
    // now all your prisma queries are run inside the same transaction.
    return prisma.cat.findMany({});
})

await findCats();
```
