21 lines
657 B
TypeScript
21 lines
657 B
TypeScript
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();
|
|
}
|
|
}
|