2023-06-09 18:21:18 +10:00
|
|
|
import { PrismaClient } from '@prisma/client';
|
2023-01-07 15:10:26 +01:00
|
|
|
|
2023-09-14 15:00:14 +10:00
|
|
|
import { getDatabaseUrl } from './helper';
|
|
|
|
|
|
2023-01-09 17:10:36 +01:00
|
|
|
declare global {
|
2023-06-09 18:21:18 +10:00
|
|
|
// We need `var` to declare a global variable in TypeScript
|
|
|
|
|
// eslint-disable-next-line no-var
|
|
|
|
|
var prisma: PrismaClient | undefined;
|
2023-01-09 17:10:36 +01:00
|
|
|
}
|
|
|
|
|
|
2023-06-09 18:21:18 +10:00
|
|
|
if (!globalThis.prisma) {
|
2023-09-14 15:00:14 +10:00
|
|
|
globalThis.prisma = new PrismaClient({ datasourceUrl: getDatabaseUrl() });
|
2023-01-10 14:48:40 +01:00
|
|
|
}
|
2023-01-09 17:10:36 +01:00
|
|
|
|
2023-09-14 15:00:14 +10:00
|
|
|
export const prisma =
|
|
|
|
|
globalThis.prisma ||
|
|
|
|
|
new PrismaClient({
|
|
|
|
|
datasourceUrl: getDatabaseUrl(),
|
|
|
|
|
});
|
2023-06-09 18:21:18 +10:00
|
|
|
|
|
|
|
|
export const getPrismaClient = () => prisma;
|