Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Transaction type #12436

Closed
ziimakc opened this issue Mar 19, 2022 · 1 comment
Closed

Export Transaction type #12436

ziimakc opened this issue Mar 19, 2022 · 1 comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client

Comments

@ziimakc
Copy link

ziimakc commented Mar 19, 2022

Problem

When using "Custom models" and "Interactive Transactions" #8664 you may want to call some operations on model and pass in current transaction. For type safety and to be consistent with latest prisma version you need a Transaction type:

export class SomeModel {
  static async someCheckOrOperation(transaction: Transaction) {
    const res = await transaction.some.findFirst();

    if (!res) {
      throw new Error();
    } else {
      doSomething();
    }
  }
}

Currently there is no way to pick this type from PrismaClient.$transaction and you forced to redefine it, that can became inconsistent with new prisma versions:

  $transaction<R>(fn: (prisma: Omit<PrismaClient, '$connect' | '$disconnect' | '$on' | '$transaction' | '$use'>) => Promise<R>, options?: { maxWait?: number, timeout?: number }): Promise<R>;

Suggested solution

Add Transaction type somewhere where it will be possible to import it:

export type Transaction = Omit<PrismaClient, '$connect' | '$disconnect' | '$on' | '$transaction' | '$use'>;
@millsp millsp added kind/feature A request for a new feature. kind/improvement An improvement to existing feature and code. tech/typescript Issue for tech TypeScript. team/client Issue for team Client. labels Mar 21, 2022
@janpio janpio added topic: client types Types in Prisma Client and removed kind/improvement An improvement to existing feature and code. labels Mar 21, 2022
@ziimakc
Copy link
Author

ziimakc commented Mar 7, 2023

Exported as Prisma.TransactionClient

@ziimakc ziimakc closed this as completed Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. team/client Issue for team Client. tech/typescript Issue for tech TypeScript. topic: client types Types in Prisma Client
Projects
None yet
Development

No branches or pull requests

3 participants