Initial commit: Kalendartool (Next.js, Prisma, Docker)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
23
lib/db/client.ts
Normal file
23
lib/db/client.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
/**
|
||||
* Globaler Prisma-Client.
|
||||
*
|
||||
* In der Entwicklung startet Next.js bei Hot Reload mehrfach Modul-Instanzen;
|
||||
* ohne Caching wuerde jede Instanz eigene Verbindungen aufbauen und die
|
||||
* Datenbank mit Verbindungen ueberfluten. Daher wird die Instanz auf
|
||||
* `globalThis` gecacht (offizielles Prisma-Rezept fuer Next.js).
|
||||
*/
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClient | undefined;
|
||||
};
|
||||
|
||||
export const prisma: PrismaClient =
|
||||
globalForPrisma.prisma ??
|
||||
new PrismaClient({
|
||||
log: process.env.NODE_ENV === 'development' ? ['warn', 'error'] : ['error'],
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
globalForPrisma.prisma = prisma;
|
||||
}
|
||||
Reference in New Issue
Block a user