Importing Prisma

In a file I created, I have the following code. Initially, I imported "prisma" everywhere I needed it. However, I discovered that this approach creates a global variable, allowing me to use "prisma" in other files without importing it explicitly. I'm unsure if this is acceptable or if I should continue importing it to avoid potential issues with using the same instance or other concerns (using next 12)
import { PrismaClient } from '@prisma/client';

let prisma;

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}

prisma = global.prisma;
}

export default prisma;
import { PrismaClient } from '@prisma/client';

let prisma;

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}

prisma = global.prisma;
}

export default prisma;
1 Reply
Papa Johns
Papa Johns8mo ago
In prisma, while creating a multiple schema models, is it possible to import schema files?