2026-10-13 22:23:09 +03:30
|
|
|
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
2026-08-29 21:06:30 +03:30
|
|
|
import { PrismaClient } from '@prisma/client';
|
2026-10-13 22:23:09 +03:30
|
|
|
import { withDeletionArchive } from '../deletions/deletion-archive';
|
|
|
|
|
|
|
|
|
|
const base = new PrismaClient();
|
|
|
|
|
const client = withDeletionArchive(base);
|
|
|
|
|
|
|
|
|
|
export interface PrismaService extends PrismaClient {}
|
2026-08-29 21:06:30 +03:30
|
|
|
|
|
|
|
|
@Injectable()
|
2026-10-13 22:23:09 +03:30
|
|
|
export class PrismaService implements OnModuleInit, OnModuleDestroy {
|
|
|
|
|
constructor() {
|
|
|
|
|
return new Proxy(this, {
|
|
|
|
|
get: (target, prop, receiver) => {
|
|
|
|
|
if (Reflect.has(target, prop)) return Reflect.get(target, prop, receiver);
|
|
|
|
|
const value = (client as unknown as Record<PropertyKey, unknown>)[prop];
|
|
|
|
|
if (typeof value === 'function') {
|
|
|
|
|
return (value as (...args: unknown[]) => unknown).bind(client);
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-29 21:06:30 +03:30
|
|
|
async onModuleInit() {
|
2026-10-13 22:23:09 +03:30
|
|
|
await client.$connect();
|
2026-08-29 21:06:30 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async onModuleDestroy() {
|
2026-10-13 22:23:09 +03:30
|
|
|
await client.$disconnect();
|
2026-08-29 21:06:30 +03:30
|
|
|
}
|
|
|
|
|
}
|
2026-10-13 22:23:09 +03:30
|
|
|
|
|
|
|
|
export type PrismaServiceClient = typeof client;
|