@20i/prisma-nestjs

A simple wrapper around the Prisma Client that makes it easy to inject into a NestJS App

Usage no npm install needed!

<script type="module">
  import 20iPrismaNestjs from 'https://cdn.skypack.dev/@20i/prisma-nestjs';
</script>

README

@20i/prisma-nestjs

A simple wrapper around the Prisma Client that makes it easy to inject into a NestJS App

Peer dependencies

    "@nestjs/common": "^7.6.17",
    "@nestjs/config": "^0.6.3",
    "@nestjs/core": "^7.6.17",
    "@nestjs/jwt": "^7.2.0",
    "@nestjs/passport": "^7.1.5",
    "@nestjs/platform-express": "^7.6.17",
    "@nestjs/swagger": "^4.8.0",
    "prisma": "2.26.0",
    "@prisma/client": "2.26.0",
    "class-transformer": "^0.4.0",
    "class-validator": "^0.13.1",
    "jsonwebtoken": "^8.5.1",
    "jwk-to-pem": "^2.0.5",
    "jwks-rsa": "^2.0.3",
    "passport": "^0.4.1",
    "passport-jwt": "^4.0.0",
    "reflect-metadata": "^0.1.13",
    "rimraf": "^3.0.2",
    "rxjs": "^6.6.6",
    "swagger-ui-express": "^4.1.6"

Installation

npm login
npm i @20i/prisma-nestjs
npx prisma generate #???

Usage

Inside a Service

@Injectable()
export class ReportsService {
  constructor(
    private readonly prisma: PrismaService,
  ) {}

  getSomething(id: number) {
    return this.prisma.aThing.findUnique({
        where: {
           id,
        }
    }
  }
}

In your app.module.ts

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { PrismaModule } from './prisma/prisma.module';
// Other imports

@Module({
  imports: [
    // global modules
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    PrismaModule, // <== here
  ],
  providers: [{ provide: APP_GUARD, useClass: GlobalJwtGuard }], // relies on the AuthModule
  controllers: [AppController],
})
export class AppModule {}

.env file

DATABASE_URL="postgresql://postgres:password@localhost:6432/postgres?schema=public"