🚑 Attempt to fix prisma not defined trpc
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user