From 2c2d05fd0a2c3c26d765f8a6beb88d907a097c1d Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 11 Feb 2024 14:54:52 +0000 Subject: refactor: Migrating to trpc instead of next's route handers --- packages/db/index.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'packages/db/index.ts') diff --git a/packages/db/index.ts b/packages/db/index.ts index 4a0f473f..e87b9515 100644 --- a/packages/db/index.ts +++ b/packages/db/index.ts @@ -1,14 +1,14 @@ import { PrismaClient } from "@prisma/client"; -const prisma = new PrismaClient({ - log: - process.env.NODE_ENV === "development" - ? ["query", "error", "warn"] - : ["error"], -}); - -// For some weird reason accessing @prisma/client from any package is causing problems (specially in error handling). -// Re export them here instead. -export * from "@prisma/client"; +const globalForPrisma = globalThis as unknown as { + prisma: PrismaClient | undefined; +}; -export default prisma; +export const prisma = + globalForPrisma.prisma ?? + new PrismaClient({ + log: + process.env.NODE_ENV === "development" + ? ["query", "error", "warn"] + : ["error"], + }); -- cgit v1.2.3-70-g09d2