Spaces:
Paused
Paused
File size: 895 Bytes
1fe7075 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import { Inject, Injectable, OnModuleDestroy } from '@nestjs/common';
import { PrismaPg } from '@prisma/adapter-pg';
import { APP_CONFIG } from '../config/app-config.js';
import type { AppConfig } from '../config/app-config.interface.js';
import { PrismaClient } from '../generated/prisma/client.js';
import { pgConnectionString } from './connection-string.js';
import { softDelete } from './soft-delete.extension.js';
const createClient = (url: string) =>
new PrismaClient({ adapter: new PrismaPg({ connectionString: pgConnectionString(url) }) }).$extends(softDelete);
type Database = ReturnType<typeof createClient>;
@Injectable()
export class PrismaService implements OnModuleDestroy {
readonly db: Database;
constructor(@Inject(APP_CONFIG) config: AppConfig) {
this.db = createClient(config.databaseUrl);
}
async onModuleDestroy() {
await this.db.$disconnect();
}
}
|