# Prisma



`@postel/prisma` is an **ORM** adapter: hand Postel your `PrismaClient` and it runs its storage through Prisma's raw query surface, sharing your connection and transactions.

<Install packages="@postel/prisma" />

`@prisma/client` is a peer dependency — you already have it in a Prisma app.

```ts nocheck title="lib/postel.ts"
import { PrismaClient } from "@prisma/client";
import { Postel } from "@postel/core";
import { PrismaStorage } from "@postel/prisma";

const prisma = new PrismaClient();

export const postel = Postel({
  outbound: {
    storage: PrismaStorage({ prisma, dialect: "postgres" }),
  },
});
```

## Options [#options]

| Option        | Notes                                                                                                                                                                                   |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `prisma`      | Your `PrismaClient` instance.                                                                                                                                                           |
| `dialect`     | `"postgres"`, `"mysql"`, or `"sqlite"` — selects the reservation strategy (`FOR UPDATE SKIP LOCKED` on Postgres/MySQL, ordered on SQLite), the capability flags, and the column codecs. |
| `autoMigrate` | Run migrations on first use (default `true`).                                                                                                                                           |
| `clock`       | Inject a clock for deterministic time in tests.                                                                                                                                         |

At runtime Postel calls Prisma only through its raw query surface (`$queryRawUnsafe` / `$executeRawUnsafe` / `$transaction`), so you add &#x2A;*no Postel models to your `schema.prisma`** — it works against any generated `PrismaClient`. `@prisma/client` is a peer dependency; the adapter imports only its type. The `dialect` names a SQL *family*, so wire-compatible engines (MariaDB, PlanetScale, libSQL/Turso, …) work via the matching dialect — see [compatible databases](/docs/storage#dialects-and-compatible-databases).

## Shared transactions [#shared-transactions]

Use Prisma's interactive transaction and pass the transaction client to `send()`:

```ts
await prisma.$transaction(async (tx) => {
  await tx.order.create({ data: { /* ... */ } });
  await postel.outbound.send({ type: "order.created", data: { /* ... */ } }, { tx });
});
```

## Migrations [#migrations]

`autoMigrate` creates Postel's tables via raw SQL on first use (version-gated, idempotent) — independent of your Prisma schema. If you'd rather Prisma own those tables, model them from the [canonical schema](/docs/storage/schema) in your `schema.prisma` and run `prisma migrate`, then start the adapter with `autoMigrate: false`.
