2
0

🚑 Attempt to fix prisma not defined trpc

This commit is contained in:
Baptiste Arnaud
2022-11-30 15:13:40 +01:00
parent c799717905
commit 3c8820b212

View File

@@ -1,15 +1,24 @@
import { PrismaClient } from 'db' /**
* Instantiates a single instance PrismaClient and save it on the global object.
* @link https://www.prisma.io/docs/support/help-articles/nextjs-prisma-client-dev-practices
*/
import { PrismaClient } from '@prisma/client'
declare const global: { prisma: PrismaClient } const prismaGlobal = global as typeof global & {
let prisma: PrismaClient prisma?: PrismaClient
}
if (process.env.NODE_ENV === 'production') { const prisma: PrismaClient =
prisma = new PrismaClient() prismaGlobal.prisma ||
} else { new PrismaClient({
if (!global.prisma) { log:
global.prisma = new PrismaClient() process.env.NODE_ENV === 'development'
} ? ['query', 'error', 'warn']
prisma = global.prisma : ['error'],
})
if (process.env.NODE_ENV !== 'production') {
prismaGlobal.prisma = prisma
} }
export default prisma export default prisma