P
Prisma4mo ago
Gg

Prisma Client: Injectable Setup Outside NestJS (with/without DI)?

In NestJS, the Prisma Client can be made injectable by extending PrismaClient and implementing lifecycle hooks like onModuleInit to manage connections. Here's how it's typically done in NestJS:
import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
}
import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
}
1. How would a similar Prisma Client setup be implemented in a non-NestJS application (for example, an Express app) without using a dependency injection tool? 2. How would this setup change if you were to use a dependency injection tool (like Tsyringe or any other DI library) in your non-NestJS application?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server