feat(db): add Prisma schema and global PrismaModule

This commit is contained in:
MastersGame
2026-11-05 23:00:46 +01:00
parent 0d7e7b7f87
commit e6e39b4f80
7 changed files with 271 additions and 4 deletions

20
prisma/prisma.service.ts Normal file
View File

@@ -0,0 +1,20 @@
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from './generated/client';
import { PrismaPg } from '@prisma/adapter-pg';
/** Prisma client shared by the whole app (global PrismaModule), connected to `DATABASE_URL` through the pg driver adapter. */
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
constructor() {
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
super({ adapter });
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy() {
await this.$disconnect();
}
}