From ba35549f10e957b0afe77ccd4a98430c0e09cb49 Mon Sep 17 00:00:00 2001 From: aditya patel Date: Mon, 16 May 2022 13:51:39 +0530 Subject: [PATCH] create: prisma module to connect with db --- src/prisma/prisma.module.ts | 9 +++++++++ src/prisma/prisma.service.ts | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/prisma/prisma.module.ts create mode 100644 src/prisma/prisma.service.ts diff --git a/src/prisma/prisma.module.ts b/src/prisma/prisma.module.ts new file mode 100644 index 0000000..7207426 --- /dev/null +++ b/src/prisma/prisma.module.ts @@ -0,0 +1,9 @@ +import { Global, Module } from '@nestjs/common'; +import { PrismaService } from './prisma.service'; + +@Global() +@Module({ + providers: [PrismaService], + exports: [PrismaService], +}) +export class PrismaModule {} diff --git a/src/prisma/prisma.service.ts b/src/prisma/prisma.service.ts new file mode 100644 index 0000000..2667678 --- /dev/null +++ b/src/prisma/prisma.service.ts @@ -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(), + ]); + } +}