Advertisement
elliottchong

Prisma db.ts

Jul 24th, 2023
2,237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import { PrismaClient } from "@prisma/client";
  2. import "server-only";
  3.  
  4. declare global {
  5. // eslint-disable-next-line no-var, no-unused-vars
  6. var cachedPrisma: PrismaClient;
  7. }
  8.  
  9. export let prisma: PrismaClient;
  10. if (process.env.NODE_ENV === "production") {
  11. prisma = new PrismaClient();
  12. } else {
  13. if (!global.cachedPrisma) {
  14. global.cachedPrisma = new PrismaClient();
  15. }
  16. prisma = global.cachedPrisma;
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement