transactionFor() function

Repositories bound to a transaction.

Signature:

export declare function transactionFor<Repositories extends object>(db: Transactional, options: RepositoryOptions): <Result>(run: (repository: Repositories) => Promise<Result>) => Promise<Result>;

Parameters

Parameter

Type

Description

db

Transactional

The client to open the transaction on.

options

RepositoryOptions

The same options repositoriesFor() takes.

Returns:

<Result>(run: (repository: Repositories) => Promise<Result>) => Promise<Result>

A function running work with transaction-bound repositories.

Remarks

Prisma Next has no nested writes — create rejects a relation key outright — so anything that used to be one nested call is now several, and they have to commit or roll back together. The callback's repositories run on the transaction's connection; throwing from it rolls back.

Example

const transaction = transactionFor<Repositories>(db, { relations });

await transaction(async repository => {
    const user = await repository.user.create<User>({ input });
    await repository.credential.create({ input: { userId: user.id } });
});

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.