Skip to content

Commit

Permalink
create: prisma module to connect with db
Browse files Browse the repository at this point in the history
  • Loading branch information
adiCacti committed May 16, 2022
1 parent 65af124 commit ba35549
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/prisma/prisma.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Global, Module } from '@nestjs/common';
import { PrismaService } from './prisma.service';

@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}
23 changes: 23 additions & 0 deletions src/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient {
constructor(config: ConfigService) {
super({
datasources: {
db: {
url: config.get('DATABASE_URL'),
},
},
});
}

cleanDb() {
return this.$transaction([
this.bookmark.deleteMany(),
this.user.deleteMany(),
]);
}
}

0 comments on commit ba35549

Please sign in to comment.