17 lines
573 B
TypeScript
17 lines
573 B
TypeScript
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
import { Pool } from 'pg';
|
|
|
|
@Injectable()
|
|
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
|
constructor() {
|
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
const adapter = new PrismaPg(pool);
|
|
super({ adapter });
|
|
}
|
|
|
|
async onModuleInit() { await this.$connect(); }
|
|
async onModuleDestroy() { await this.$disconnect(); }
|
|
}
|