Skip to content

Instantly share code, notes, and snippets.

@alternacrow
Last active November 17, 2023 05:34
Show Gist options
  • Save alternacrow/8753f854804de104866c740db7868e40 to your computer and use it in GitHub Desktop.
Save alternacrow/8753f854804de104866c740db7868e40 to your computer and use it in GitHub Desktop.
Prisma

Prisma

Query optimization

Solving the n+1 problem
https://www.prisma.io/docs/guides/performance-and-optimization/query-optimization-performance

Transaction

https://www.prisma.io/docs/concepts/components/prisma-client/transactions

  • timeout: The maximum amount of time the interactive transaction can run before being canceled and rolled back. The default value is 5 seconds.
    • デフォルトのタイムアウトは 5 秒

使い方

書き方は 2 種類

const [user, profile] = await prisma.$transaction([
  prisma.user.create({ data: ...{} }),
  prisma.profile.create({ data: ...{} }),
]);
const [user, profile] = await prisma.$transaction(async (tx) => {
  const user = await tx.user.create({ data: ...{} });
  const profile = await tx.profile.create({ data: ...{} });

  return [user, profile];
});

Jest

jest.resetModules() https://jestjs.io/docs/ja/jest-object#jestresetmodules jest.unmock() https://jestjs.io/docs/ja/jest-object#jestunmockmodulename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment