├── .node-version ├── docs ├── .prettierignore ├── .npmrc ├── public │ └── favicon.png ├── src │ ├── env.d.ts │ ├── content │ │ ├── config.ts │ │ └── docs │ │ │ ├── custom-prisma-service.md │ │ │ ├── installation.md │ │ │ ├── prisma-logging.md │ │ │ ├── basic-usage.md │ │ │ ├── prisma-middleware.md │ │ │ ├── logging-middleware.md │ │ │ ├── schematics.md │ │ │ ├── configuration.md │ │ │ ├── query-logging-extension.md │ │ │ ├── rust-free-and-driver-adapter.md │ │ │ └── custom-prisma-client-location.md │ ├── icons │ │ ├── moon.svg │ │ ├── sun.svg │ │ ├── twitter.svg │ │ ├── prisma.svg │ │ └── github.svg │ ├── components │ │ ├── HeadCommon.astro │ │ ├── ThemeButton.astro │ │ ├── TableOfContents.astro │ │ ├── Search.css │ │ ├── PrevNextNavigation.astro │ │ ├── Navigation.astro │ │ ├── Header.astro │ │ ├── Footer.astro │ │ └── Search.tsx │ ├── pages │ │ ├── docs │ │ │ ├── [...slug].astro │ │ │ └── examples.astro │ │ └── 404.astro │ ├── layouts │ │ ├── CustomDoc.astro │ │ ├── Base.astro │ │ └── Doc.astro │ └── config.ts ├── .prettierrc.json ├── .gitignore ├── astro.config.mjs ├── tsconfig.json ├── package.json ├── tailwind.config.cjs └── README.md ├── .prettierignore ├── lib ├── interfaces │ ├── index.ts │ └── prisma-module-options.interface.ts ├── prisma.constants.ts ├── custom │ ├── custom-prisma.constants.ts │ ├── index.ts │ ├── custom-prisma.service.ts │ ├── custom-prisma-options.ts │ └── custom-prisma.module.ts ├── index.ts ├── prisma.service.ts ├── prisma.module.ts └── prisma-client-exception.filter.ts ├── .eslintignore ├── examples ├── basics │ ├── .prettierrc │ ├── tsconfig.build.json │ ├── prisma │ │ ├── migrations │ │ │ ├── migration_lock.toml │ │ │ └── 20221005145324_init │ │ │ │ └── migration.sql │ │ ├── schema.prisma │ │ └── seed.ts │ ├── test │ │ ├── jest-e2e.json │ │ └── app.e2e-spec.ts │ ├── nest-cli.json │ ├── src │ │ ├── app.service.ts │ │ ├── main.ts │ │ ├── app.controller.ts │ │ ├── app.controller.spec.ts │ │ └── app.module.ts │ ├── .gitignore │ ├── .eslintrc.js │ ├── tsconfig.json │ ├── README.md │ └── package.json ├── driver │ ├── .prettierrc │ ├── tsconfig.build.json │ ├── prisma │ │ ├── migrations │ │ │ ├── migration_lock.toml │ │ │ └── 20250930111755_init │ │ │ │ └── migration.sql │ │ ├── schema.prisma │ │ └── seed.ts │ ├── nest-cli.json │ ├── test │ │ ├── jest-e2e.json │ │ └── app.e2e-spec.ts │ ├── src │ │ ├── main.ts │ │ ├── app.controller.ts │ │ ├── prisma.extension.ts │ │ ├── generated │ │ │ └── prisma │ │ │ │ ├── enums.ts │ │ │ │ ├── models.ts │ │ │ │ ├── browser.ts │ │ │ │ ├── client.ts │ │ │ │ └── internal │ │ │ │ └── prismaNamespaceBrowser.ts │ │ ├── app.service.ts │ │ ├── app.module.ts │ │ └── app.controller.spec.ts │ ├── prisma.config.ts │ ├── tsconfig.json │ ├── .gitignore │ ├── eslint.config.mjs │ ├── package.json │ └── README.md ├── fastify │ ├── .prettierrc │ ├── src │ │ ├── dto │ │ │ └── create-user.dto.ts │ │ ├── app.module.ts │ │ ├── main.ts │ │ ├── app.controller.spec.ts │ │ ├── app.controller.ts │ │ └── app.service.ts │ ├── tsconfig.build.json │ ├── prisma │ │ ├── migrations │ │ │ ├── migration_lock.toml │ │ │ └── 20221005145324_init │ │ │ │ └── migration.sql │ │ ├── schema.prisma │ │ └── seed.ts │ ├── nest-cli.json │ ├── test │ │ ├── jest-e2e.json │ │ └── app.e2e-spec.ts │ ├── .gitignore │ ├── .eslintrc.js │ ├── README.md │ ├── tsconfig.json │ └── package.json ├── graphql │ ├── .prettierrc │ ├── tsconfig.build.json │ ├── prisma │ │ ├── migrations │ │ │ ├── migration_lock.toml │ │ │ └── 20230619070523_user │ │ │ │ └── migration.sql │ │ ├── schema.prisma │ │ ├── seed.ts │ │ └── seed copy.ts │ ├── nest-cli.json │ ├── test │ │ ├── jest-e2e.json │ │ └── app.e2e-spec.ts │ ├── src │ │ ├── user │ │ │ ├── dto │ │ │ │ ├── create-user.input.ts │ │ │ │ └── update-user.input.ts │ │ │ ├── user.module.ts │ │ │ ├── entities │ │ │ │ └── user.entity.ts │ │ │ ├── user.service.ts │ │ │ └── user.resolver.ts │ │ ├── main.ts │ │ ├── schema.gql │ │ └── app.module.ts │ ├── .gitignore │ ├── .eslintrc.js │ ├── tsconfig.json │ ├── package.json │ └── README.md └── extensions │ ├── .prettierrc │ ├── tsconfig.build.json │ ├── prisma │ ├── migrations │ │ ├── migration_lock.toml │ │ └── 20221005145324_init │ │ │ └── migration.sql │ ├── schema.prisma │ └── seed.ts │ ├── nest-cli.json │ ├── test │ ├── jest-e2e.json │ └── app.e2e-spec.ts │ ├── src │ ├── main.ts │ ├── app.module.ts │ ├── app.controller.ts │ ├── app.controller.spec.ts │ ├── query-logging.extension.ts │ ├── app.service.ts │ └── prisma.extension.ts │ ├── .gitignore │ ├── .eslintrc.js │ ├── tsconfig.json │ ├── README.md │ └── package.json ├── schematics ├── nestjs-prisma │ ├── templates │ │ ├── docker │ │ │ ├── common │ │ │ │ ├── .dockerignore │ │ │ │ └── Dockerfile │ │ │ ├── mysql │ │ │ │ ├── docker-compose.yml │ │ │ │ └── .env │ │ │ └── postgresql │ │ │ │ ├── docker-compose.yml │ │ │ │ └── .env │ │ └── services │ │ │ └── src │ │ │ └── prisma │ │ │ ├── __name@dasherize__.module.ts │ │ │ ├── __name@dasherize__.service.ts │ │ │ └── __name@dasherize__.service.spec.ts │ ├── dependencies.ts │ ├── npm-scripts.ts │ ├── schema.ts │ ├── utils │ │ └── get-latest-dependency-version.ts │ └── schema.json ├── collection.json └── prisma-init │ └── index.ts ├── .vscode ├── extensions.json └── launch.json ├── .prettierrc ├── prisma ├── migrations │ ├── migration_lock.toml │ └── 20221005130612_init │ │ └── migration.sql └── schema.prisma ├── tsconfig.lib.json ├── .npmignore ├── .gitignore ├── prisma.config.ts ├── tsconfig.json ├── tsconfig.schematics.json ├── .eslintrc.js ├── .github └── workflows │ ├── node.js.yml │ └── docs.yml ├── LICENSE ├── package.json └── README.md /.node-version: -------------------------------------------------------------------------------- 1 | 20.19.5 -------------------------------------------------------------------------------- /docs/.prettierignore: -------------------------------------------------------------------------------- 1 | package-lock.json -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | schematics/*/templates/* 2 | schematics/*/*.d.ts -------------------------------------------------------------------------------- /lib/interfaces/index.ts: -------------------------------------------------------------------------------- 1 | export * from './prisma-module-options.interface'; 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | schematics/**/*.d.ts 2 | schematics/nestjs-prisma/templates/**/*.ts -------------------------------------------------------------------------------- /docs/.npmrc: -------------------------------------------------------------------------------- 1 | # Expose Astro dependencies for `pnpm` users 2 | shamefully-hoist=true 3 | -------------------------------------------------------------------------------- /examples/basics/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /examples/driver/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /examples/fastify/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /examples/graphql/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /lib/prisma.constants.ts: -------------------------------------------------------------------------------- 1 | export const PRISMA_SERVICE_OPTIONS = 'PRISMA_SERVICE_OPTIONS'; 2 | -------------------------------------------------------------------------------- /examples/extensions/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /lib/custom/custom-prisma.constants.ts: -------------------------------------------------------------------------------- 1 | export const CUSTOM_PRISMA_CLIENT = 'CUSTOM_PRISMA_CLIENT'; 2 | -------------------------------------------------------------------------------- /docs/public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notiz-dev/nestjs-prisma/HEAD/docs/public/favicon.png -------------------------------------------------------------------------------- /docs/src/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/docker/common/.dockerignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | node_modules/ 3 | dist/ 4 | npm-debug.log -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["astro-build.astro-vscode"], 3 | "unwantedRecommendations": [] 4 | } 5 | -------------------------------------------------------------------------------- /examples/fastify/src/dto/create-user.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateUserDto { 2 | email: string; 3 | name?: string; 4 | } 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "plugins": ["prettier-plugin-organize-imports"] 5 | } 6 | -------------------------------------------------------------------------------- /docs/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "plugins": ["prettier-plugin-astro", "prettier-plugin-tailwindcss"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/basics/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/driver/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/extensions/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/fastify/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/graphql/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /lib/custom/index.ts: -------------------------------------------------------------------------------- 1 | export * from './custom-prisma-options'; 2 | export * from './custom-prisma.module'; 3 | export * from './custom-prisma.service'; 4 | -------------------------------------------------------------------------------- /prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /examples/basics/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /examples/extensions/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /examples/fastify/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /examples/graphql/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "sqlite" -------------------------------------------------------------------------------- /examples/driver/prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (e.g., Git) 3 | provider = "sqlite" 4 | -------------------------------------------------------------------------------- /examples/driver/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/nest-cli", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/fastify/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/nest-cli", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/graphql/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/nest-cli", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/extensions/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/nest-cli", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /lib/index.ts: -------------------------------------------------------------------------------- 1 | export * from './custom'; 2 | 3 | export * from './interfaces'; 4 | export * from './prisma-client-exception.filter'; 5 | export * from './prisma.constants'; 6 | export * from './prisma.module'; 7 | export * from './prisma.service'; 8 | -------------------------------------------------------------------------------- /examples/basics/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/driver/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "outDir": "./dist" 6 | }, 7 | "include": ["lib/**/*"], 8 | "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /examples/extensions/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/fastify/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/graphql/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "command": "./node_modules/.bin/astro dev", 6 | "name": "Development server", 7 | "request": "launch", 8 | "type": "node-terminal" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /examples/graphql/src/user/dto/create-user.input.ts: -------------------------------------------------------------------------------- 1 | import { InputType, Field } from '@nestjs/graphql'; 2 | 3 | @InputType() 4 | export class CreateUserInput { 5 | @Field(() => String) 6 | name: string; 7 | 8 | @Field(() => String) 9 | email: string; 10 | } 11 | -------------------------------------------------------------------------------- /examples/driver/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(process.env.PORT ?? 3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /examples/extensions/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | 7 | await app.listen(3000); 8 | } 9 | bootstrap(); 10 | -------------------------------------------------------------------------------- /docs/src/content/config.ts: -------------------------------------------------------------------------------- 1 | import { z, defineCollection } from 'astro:content'; 2 | 3 | const docsCollection = defineCollection({ 4 | schema: z.object({ 5 | title: z.string(), 6 | }), 7 | }); 8 | 9 | export const collections = { 10 | docs: docsCollection, 11 | }; 12 | -------------------------------------------------------------------------------- /examples/graphql/src/user/user.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { UserService } from './user.service'; 3 | import { UserResolver } from './user.resolver'; 4 | 5 | @Module({ 6 | providers: [UserResolver, UserService], 7 | }) 8 | export class UserModule {} 9 | -------------------------------------------------------------------------------- /examples/basics/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/nest-cli", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true, 7 | "builder": "swc", 8 | "typeCheck": true 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /examples/basics/prisma/migrations/20221005145324_init/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" TEXT NOT NULL PRIMARY KEY, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT 6 | ); 7 | 8 | -- CreateIndex 9 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 10 | -------------------------------------------------------------------------------- /examples/driver/prisma/migrations/20250930111755_init/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" TEXT NOT NULL PRIMARY KEY, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT 6 | ); 7 | 8 | -- CreateIndex 9 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 10 | -------------------------------------------------------------------------------- /examples/fastify/prisma/migrations/20221005145324_init/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" TEXT NOT NULL PRIMARY KEY, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT 6 | ); 7 | 8 | -- CreateIndex 9 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 10 | -------------------------------------------------------------------------------- /examples/graphql/prisma/migrations/20230619070523_user/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" TEXT NOT NULL PRIMARY KEY, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT 6 | ); 7 | 8 | -- CreateIndex 9 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 10 | -------------------------------------------------------------------------------- /prisma/migrations/20221005130612_init/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT 6 | ); 7 | 8 | -- CreateIndex 9 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 10 | -------------------------------------------------------------------------------- /examples/extensions/prisma/migrations/20221005145324_init/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "User" ( 3 | "id" TEXT NOT NULL PRIMARY KEY, 4 | "email" TEXT NOT NULL, 5 | "name" TEXT 6 | ); 7 | 8 | -- CreateIndex 9 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 10 | -------------------------------------------------------------------------------- /examples/graphql/src/user/dto/update-user.input.ts: -------------------------------------------------------------------------------- 1 | import { CreateUserInput } from './create-user.input'; 2 | import { Field, InputType, PartialType } from '@nestjs/graphql'; 3 | 4 | @InputType() 5 | export class UpdateUserInput extends PartialType(CreateUserInput) { 6 | @Field(() => String) 7 | id: string; 8 | } 9 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Ignores TypeScript files, but keeps definitions. 2 | !*.d.ts 3 | 4 | # source 5 | lib 6 | package-lock.json 7 | .prettierrc 8 | prisma/ 9 | .vscode/ 10 | .github/ 11 | .eslintignore 12 | .eslintrc.js 13 | .node-version 14 | .prettierignore 15 | 16 | # misc 17 | .DS_Store 18 | 19 | examples/ 20 | 21 | # docs 22 | docs/ -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # build output 2 | dist/ 3 | .output/ 4 | 5 | # dependencies 6 | node_modules/ 7 | 8 | # logs 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | pnpm-debug.log* 13 | 14 | 15 | # environment variables 16 | .env 17 | .env.production 18 | 19 | # macOS-specific files 20 | .DS_Store 21 | 22 | .astro 23 | -------------------------------------------------------------------------------- /examples/graphql/src/user/entities/user.entity.ts: -------------------------------------------------------------------------------- 1 | import { ObjectType, Field } from '@nestjs/graphql'; 2 | 3 | @ObjectType() 4 | export class User { 5 | @Field(() => String) 6 | id: string; 7 | 8 | @Field(() => String, { nullable: true }) 9 | name: string | null; 10 | 11 | @Field(() => String) 12 | email: string; 13 | } 14 | -------------------------------------------------------------------------------- /examples/driver/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | users() { 10 | return this.appService.users(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # lib 2 | dist 3 | 4 | # Schematics 5 | schematics/**/*.js 6 | schematics/**/*.js.map 7 | schematics/**/*.d.ts 8 | 9 | # IDEs 10 | .idea/ 11 | jsconfig.json 12 | 13 | # Misc 14 | node_modules/ 15 | npm-debug.log* 16 | yarn-error.log* 17 | 18 | # Mac OSX Finder files. 19 | **/.DS_Store 20 | .DS_Store 21 | 22 | .env 23 | 24 | prisma/dev.db* 25 | -------------------------------------------------------------------------------- /examples/driver/src/prisma.extension.ts: -------------------------------------------------------------------------------- 1 | import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3'; 2 | import { PrismaClient } from './generated/prisma/client'; 3 | 4 | const adapter = new PrismaBetterSqlite3({ url: 'file:./prisma/dev.db' }); 5 | export const prisma = new PrismaClient({ adapter }); 6 | 7 | export type PrismaClientType = typeof prisma; 8 | -------------------------------------------------------------------------------- /prisma.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import { defineConfig } from 'prisma/config'; 3 | 4 | export default defineConfig({ 5 | schema: path.join('prisma', 'schema.prisma'), 6 | migrations: { 7 | path: './prisma/migrations', 8 | seed: 'tsx ./prisma/seed.ts', 9 | }, 10 | datasource: { 11 | url: 'file:./dev.db', 12 | }, 13 | }); 14 | -------------------------------------------------------------------------------- /examples/driver/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | generator client { 2 | provider = "prisma-client" 3 | output = "../src/generated/prisma" 4 | engineType = "client" 5 | moduleFormat = "cjs" 6 | } 7 | 8 | datasource db { 9 | provider = "sqlite" 10 | } 11 | 12 | model User { 13 | id String @id @default(cuid()) 14 | email String @unique 15 | name String? 16 | } 17 | -------------------------------------------------------------------------------- /examples/fastify/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { PrismaModule } from 'nestjs-prisma'; 2 | import { Module } from '@nestjs/common'; 3 | import { AppController } from './app.controller'; 4 | import { AppService } from './app.service'; 5 | 6 | @Module({ 7 | imports: [PrismaModule], 8 | controllers: [AppController], 9 | providers: [AppService], 10 | }) 11 | export class AppModule {} 12 | -------------------------------------------------------------------------------- /examples/driver/prisma.config.ts: -------------------------------------------------------------------------------- 1 | import path from 'node:path'; 2 | import { defineConfig } from 'prisma/config'; 3 | 4 | export default defineConfig({ 5 | schema: path.join('prisma', 'schema.prisma'), 6 | migrations: { 7 | path: './prisma/migrations', 8 | seed: 'tsx ./prisma/seed.ts', 9 | }, 10 | datasource: { 11 | url: 'file:./prisma/dev.db', 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /docs/src/icons/moon.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /docs/src/icons/sun.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | -------------------------------------------------------------------------------- /lib/custom/custom-prisma.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable } from '@nestjs/common'; 2 | import { PrismaClientLike } from './custom-prisma-options'; 3 | import { CUSTOM_PRISMA_CLIENT } from './custom-prisma.constants'; 4 | 5 | @Injectable() 6 | export class CustomPrismaService { 7 | constructor( 8 | @Inject(CUSTOM_PRISMA_CLIENT) 9 | public client: Client, 10 | ) {} 11 | } 12 | -------------------------------------------------------------------------------- /examples/basics/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | datasource db { 5 | provider = "sqlite" 6 | url = "file:dev.db" 7 | } 8 | 9 | generator client { 10 | provider = "prisma-client-js" 11 | } 12 | 13 | model User { 14 | id String @id @default(cuid()) 15 | email String @unique 16 | name String? 17 | } 18 | -------------------------------------------------------------------------------- /examples/fastify/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | datasource db { 5 | provider = "sqlite" 6 | url = "file:dev.db" 7 | } 8 | 9 | generator client { 10 | provider = "prisma-client-js" 11 | } 12 | 13 | model User { 14 | id String @id @default(cuid()) 15 | email String @unique 16 | name String? 17 | } 18 | -------------------------------------------------------------------------------- /examples/graphql/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | generator client { 5 | provider = "prisma-client-js" 6 | } 7 | 8 | datasource db { 9 | provider = "sqlite" 10 | url = "file:dev.db" 11 | } 12 | 13 | model User { 14 | id String @id @default(cuid()) 15 | email String @unique 16 | name String? 17 | } 18 | -------------------------------------------------------------------------------- /examples/basics/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from '@prisma/client'; 2 | 3 | const prisma = new PrismaClient(); 4 | 5 | async function main() { 6 | await prisma.user.create({ 7 | data: { 8 | name: 'Ham Burger', 9 | email: 'ham@burger.dev', 10 | }, 11 | }); 12 | } 13 | 14 | main() 15 | .catch((e) => console.error(e)) 16 | .finally(async () => { 17 | await prisma.$disconnect(); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/extensions/prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | datasource db { 5 | provider = "sqlite" 6 | url = "file:dev.db" 7 | } 8 | 9 | generator client { 10 | provider = "prisma-client-js" 11 | } 12 | 13 | model User { 14 | id String @id @default(cuid()) 15 | email String @unique 16 | name String? 17 | } 18 | -------------------------------------------------------------------------------- /examples/fastify/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from '@prisma/client'; 2 | 3 | const prisma = new PrismaClient(); 4 | 5 | async function main() { 6 | await prisma.user.create({ 7 | data: { 8 | name: 'Ham Burger', 9 | email: 'ham@burger.dev', 10 | }, 11 | }); 12 | } 13 | 14 | main() 15 | .catch((e) => console.error(e)) 16 | .finally(async () => { 17 | await prisma.$disconnect(); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/graphql/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from '@prisma/client'; 2 | 3 | const prisma = new PrismaClient(); 4 | 5 | async function main() { 6 | await prisma.user.create({ 7 | data: { 8 | name: 'Ham Burger', 9 | email: 'ham@burger.dev', 10 | }, 11 | }); 12 | } 13 | 14 | main() 15 | .catch((e) => console.error(e)) 16 | .finally(async () => { 17 | await prisma.$disconnect(); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/extensions/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from '@prisma/client'; 2 | 3 | const prisma = new PrismaClient(); 4 | 5 | async function main() { 6 | await prisma.user.create({ 7 | data: { 8 | name: 'Ham Burger', 9 | email: 'ham@burger.dev', 10 | }, 11 | }); 12 | } 13 | 14 | main() 15 | .catch((e) => console.error(e)) 16 | .finally(async () => { 17 | await prisma.$disconnect(); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/graphql/prisma/seed copy.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from '@prisma/client'; 2 | 3 | const prisma = new PrismaClient(); 4 | 5 | async function main() { 6 | await prisma.user.create({ 7 | data: { 8 | name: 'Ham Burger', 9 | email: 'ham@burger.dev', 10 | }, 11 | }); 12 | } 13 | 14 | main() 15 | .catch((e) => console.error(e)) 16 | .finally(async () => { 17 | await prisma.$disconnect(); 18 | }); 19 | -------------------------------------------------------------------------------- /examples/driver/src/generated/prisma/enums.ts: -------------------------------------------------------------------------------- 1 | 2 | /* !!! This is code generated by Prisma. Do not edit directly. !!! */ 3 | /* eslint-disable */ 4 | // biome-ignore-all lint: generated file 5 | // @ts-nocheck 6 | /* 7 | * This file exports all enum related types from the schema. 8 | * 9 | * 🟢 You can import this file directly. 10 | */ 11 | 12 | 13 | 14 | // This file is empty because there are no enums in the schema. 15 | export {} 16 | -------------------------------------------------------------------------------- /examples/driver/src/generated/prisma/models.ts: -------------------------------------------------------------------------------- 1 | 2 | /* !!! This is code generated by Prisma. Do not edit directly. !!! */ 3 | /* eslint-disable */ 4 | // biome-ignore-all lint: generated file 5 | // @ts-nocheck 6 | /* 7 | * This is a barrel export file for all models and their related types. 8 | * 9 | * 🟢 You can import this file directly. 10 | */ 11 | export type * from './models/User.js' 12 | export type * from './commonInputTypes.js' -------------------------------------------------------------------------------- /schematics/nestjs-prisma/dependencies.ts: -------------------------------------------------------------------------------- 1 | import { NodeDependencyType } from '@schematics/angular/utility/dependencies'; 2 | 3 | export interface Dependency { 4 | name: string; 5 | type: NodeDependencyType; 6 | } 7 | 8 | export const dependencies: Dependency[] = [ 9 | { 10 | name: 'prisma', 11 | type: NodeDependencyType.Dev, 12 | }, 13 | { 14 | name: '@prisma/client', 15 | type: NodeDependencyType.Default, 16 | }, 17 | ]; 18 | -------------------------------------------------------------------------------- /examples/basics/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { PrismaService } from 'nestjs-prisma'; 3 | 4 | @Injectable() 5 | export class AppService { 6 | constructor(private prisma: PrismaService) {} 7 | 8 | users() { 9 | return this.prisma.user.findMany(); 10 | } 11 | 12 | user(userId: string) { 13 | return this.prisma.user.findFirstOrThrow({ 14 | where: { id: userId }, 15 | }); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /docs/src/components/HeadCommon.astro: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 15 | -------------------------------------------------------------------------------- /examples/graphql/src/main.ts: -------------------------------------------------------------------------------- 1 | import { HttpAdapterHost, NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | import { PrismaClientExceptionFilter } from 'nestjs-prisma'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | 8 | const { httpAdapter } = app.get(HttpAdapterHost); 9 | app.useGlobalFilters(new PrismaClientExceptionFilter(httpAdapter)); 10 | 11 | await app.listen(3000); 12 | } 13 | bootstrap(); 14 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/services/src/prisma/__name@dasherize__.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { <%= classify(name) %>Service } from './<%= dasherize(name) %>.service'; 3 | 4 | /** 5 | * See optional instruction for global modules https://docs.nestjs.com/modules#global-modules 6 | */ 7 | @Module({ 8 | providers: [<%= classify(name) %>Service], 9 | exports: [<%= classify(name) %>Service], 10 | }) 11 | export class <%= classify(name) %>Module {} 12 | -------------------------------------------------------------------------------- /schematics/collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json", 3 | "schematics": { 4 | "nest-add": { 5 | "description": "Adds Prisma support to the NestJS application", 6 | "factory": "./nestjs-prisma/index#nestjsPrismaAdd", 7 | "schema": "./nestjs-prisma/schema.json" 8 | }, 9 | "prisma-init": { 10 | "description": "Run Prisma init", 11 | "factory": "./prisma-init/index#prismaInit" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "paths": { 15 | "@prisma/client": ["node_modules/.prisma/client/client.ts"] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/basics/src/main.ts: -------------------------------------------------------------------------------- 1 | import { HttpAdapterHost, NestFactory } from '@nestjs/core'; 2 | import { PrismaClientExceptionFilter } from 'nestjs-prisma'; 3 | import { AppModule } from './app.module'; 4 | 5 | async function bootstrap() { 6 | const app = await NestFactory.create(AppModule); 7 | 8 | // prisma exception filter 9 | const { httpAdapter } = app.get(HttpAdapterHost); 10 | app.useGlobalFilters(new PrismaClientExceptionFilter(httpAdapter)); 11 | 12 | await app.listen(3000); 13 | } 14 | bootstrap(); 15 | -------------------------------------------------------------------------------- /examples/driver/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import { prisma } from '../src/prisma.extension'; 2 | 3 | async function main() { 4 | console.log('Seeding database...'); 5 | console.time('Seeding complete 🌱'); 6 | 7 | // TODO seed development data 8 | await prisma.user.deleteMany({}); 9 | 10 | await prisma.user.create({ 11 | data: { 12 | name: 'Ham Burger', 13 | email: 'ham@burger.dev', 14 | }, 15 | }); 16 | 17 | console.timeEnd('Seeding complete 🌱'); 18 | } 19 | 20 | main().catch((e) => console.log(e)); 21 | -------------------------------------------------------------------------------- /prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | datasource db { 5 | provider = "sqlite" 6 | } 7 | 8 | generator client { 9 | provider = "prisma-client" 10 | // only generated to node_modules for the old @prisma/client import, to build the library 11 | output = "../node_modules/.prisma/client" 12 | } 13 | 14 | model User { 15 | id Int @id @default(autoincrement()) 16 | email String @unique 17 | name String? 18 | } 19 | -------------------------------------------------------------------------------- /docs/astro.config.mjs: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'astro/config'; 2 | 3 | // css 4 | import tailwind from '@astrojs/tailwind'; 5 | 6 | // seo 7 | import sitemap from '@astrojs/sitemap'; 8 | import robotsTxt from 'astro-robots-txt'; 9 | 10 | // frameworks 11 | import alpinejs from '@astrojs/alpinejs'; 12 | import react from '@astrojs/react'; 13 | 14 | // https://astro.build/config 15 | export default defineConfig({ 16 | site: 'https://nestjs-prisma.dev', 17 | integrations: [tailwind(), sitemap(), robotsTxt(), alpinejs(), react()], 18 | }); 19 | -------------------------------------------------------------------------------- /examples/basics/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Param } from '@nestjs/common'; 2 | import { User } from '@prisma/client'; 3 | import { AppService } from './app.service'; 4 | 5 | @Controller() 6 | export class AppController { 7 | constructor(private readonly appService: AppService) {} 8 | 9 | @Get() 10 | users(): Promise { 11 | return this.appService.users(); 12 | } 13 | 14 | @Get(':userId') 15 | user(@Param('userId') userId: string): Promise { 16 | return this.appService.user(userId); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /docs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/tsconfig", 3 | "extends": "astro/tsconfigs/strict", 4 | "compilerOptions": { 5 | "target": "ESNext", 6 | "module": "ESNext", 7 | "moduleResolution": "node", 8 | "resolveJsonModule": true, 9 | "isolatedModules": true, 10 | "noEmit": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "esModuleInterop": true, 13 | "strict": true, 14 | "importsNotUsedAsValues": "error", 15 | "jsx": "react-jsx", 16 | "jsxImportSource": "react" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/driver/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable } from '@nestjs/common'; 2 | import { CustomPrismaService } from 'nestjs-prisma/dist/custom'; 3 | import { PrismaClientType } from './prisma.extension'; 4 | 5 | @Injectable() 6 | export class AppService { 7 | constructor( 8 | // ✅ use `ExtendedPrismaClient` from extension for correct type-safety 9 | @Inject('PrismaService') 10 | private prismaService: CustomPrismaService, 11 | ) {} 12 | 13 | users() { 14 | return this.prismaService.client.user.findMany(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/src/icons/twitter.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/services/src/prisma/__name@dasherize__.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, OnModuleInit } from '@nestjs/common'; 2 | import { PrismaClient } from '@prisma/client'; 3 | 4 | @Injectable() 5 | export class <%= classify(name) %>Service extends PrismaClient 6 | implements OnModuleInit { 7 | 8 | constructor() { 9 | super(); 10 | } 11 | 12 | /** 13 | * The onModuleInit is optional — if you leave it out, Prisma will connect lazily on its first call to the database. 14 | */ 15 | async onModuleInit() { 16 | await this.$connect(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/driver/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | import { CustomPrismaModule } from 'nestjs-prisma/dist/custom'; 5 | import { prisma } from './prisma.extension'; 6 | 7 | @Module({ 8 | imports: [ 9 | CustomPrismaModule.forRootAsync({ 10 | name: 'PrismaService', 11 | useFactory: () => { 12 | return prisma; 13 | }, 14 | }), 15 | ], 16 | controllers: [AppController], 17 | providers: [AppService], 18 | }) 19 | export class AppModule {} 20 | -------------------------------------------------------------------------------- /examples/graphql/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json 36 | 37 | 38 | prisma/dev.db -------------------------------------------------------------------------------- /examples/basics/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json 36 | 37 | # prisma 38 | prisma/dev.db* -------------------------------------------------------------------------------- /examples/extensions/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json 36 | 37 | # prisma 38 | prisma/dev.db* -------------------------------------------------------------------------------- /examples/fastify/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json 36 | 37 | # prisma 38 | prisma/dev.db* -------------------------------------------------------------------------------- /docs/src/pages/docs/[...slug].astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { CollectionEntry, getCollection } from 'astro:content'; 3 | import Layout from '../../layouts/Doc.astro'; 4 | 5 | export async function getStaticPaths() { 6 | const docs = await getCollection('docs'); 7 | return docs.map((doc) => ({ 8 | params: { slug: doc.slug }, 9 | props: doc, 10 | })); 11 | } 12 | 13 | type Props = CollectionEntry<'docs'>; 14 | 15 | const project = Astro.props; 16 | const { Content, headings } = await project.render(); 17 | --- 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/extensions/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { CustomPrismaModule } from 'nestjs-prisma'; 3 | import { AppController } from './app.controller'; 4 | import { AppService } from './app.service'; 5 | import { extendedPrismaClient } from './prisma.extension'; 6 | 7 | @Module({ 8 | imports: [ 9 | CustomPrismaModule.forRootAsync({ 10 | name: 'PrismaService', 11 | useFactory: () => { 12 | return extendedPrismaClient; 13 | }, 14 | }), 15 | ], 16 | controllers: [AppController], 17 | providers: [AppService], 18 | }) 19 | export class AppModule {} 20 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/docker/common/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:<%= dockerNodeImageVersion %> AS builder 2 | 3 | # Create app directory 4 | WORKDIR /app 5 | 6 | # A wildcard is used to ensure both package.json AND package-lock.json are copied 7 | COPY package*.json ./ 8 | COPY prisma ./prisma/ 9 | 10 | # Install app dependencies 11 | RUN npm install 12 | 13 | COPY . . 14 | 15 | RUN npm run build 16 | 17 | FROM node:<%= dockerNodeImageVersion %> 18 | 19 | COPY --from=builder /app/node_modules ./node_modules 20 | COPY --from=builder /app/package*.json ./ 21 | COPY --from=builder /app/dist ./dist 22 | 23 | EXPOSE 3000 24 | CMD [ "npm", "run", "start:prod" ] -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/docker/mysql/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | nest-api: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | container_name: nest-api 8 | restart: always 9 | ports: 10 | - '3000:3000' 11 | depends_on: 12 | - nest-mysql 13 | env_file: 14 | - .env 15 | 16 | nest-mysql: 17 | image: mysql:8 18 | container_name: nest-mysql 19 | restart: always 20 | ports: 21 | - '3306:3306' 22 | env_file: 23 | - .env 24 | volumes: 25 | - nest-mysql:/var/lib/mysql 26 | 27 | volumes: 28 | nest-mysql: 29 | name: nest-mysql-db 30 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/docker/mysql/.env: -------------------------------------------------------------------------------- 1 | MYSQL_ROOT_USER=root 2 | MYSQL_ROOT_PASSWORD=rootTopsecret 3 | MYSQL_DATABASE=mydb 4 | 5 | # See https://www.prisma.io/docs/concepts/database-connectors/mysql 6 | # Host value is the default container name for mysql - @nest-mysql:5432 7 | # change it when changing the container name 8 | DATABASE_URL=mysql://${MYSQL_ROOT_USER}:${MYSQL_ROOT_PASSWORD}@nest-mysql:3306/${MYSQL_DATABASE} 9 | # To have acccess to the database container from your local machine 10 | # use the DATABASE_URL below which replaces nest-mysql (container name) with localhost 11 | #DATABASE_URL=mysql://${MYSQL_ROOT_USER}:${MYSQL_ROOT_PASSWORD}@localhost:3306/${MYSQL_DATABASE} -------------------------------------------------------------------------------- /examples/fastify/src/main.ts: -------------------------------------------------------------------------------- 1 | import { HttpAdapterHost, NestFactory } from '@nestjs/core'; 2 | import { 3 | FastifyAdapter, 4 | NestFastifyApplication, 5 | } from '@nestjs/platform-fastify'; 6 | import { PrismaClientExceptionFilter } from 'nestjs-prisma'; 7 | import { AppModule } from './app.module'; 8 | 9 | async function bootstrap() { 10 | const app = await NestFactory.create( 11 | AppModule, 12 | new FastifyAdapter(), 13 | ); 14 | 15 | // prisma exception filter 16 | const { httpAdapter } = app.get(HttpAdapterHost); 17 | app.useGlobalFilters(new PrismaClientExceptionFilter(httpAdapter)); 18 | 19 | await app.listen(3000); 20 | } 21 | bootstrap(); 22 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/docker/postgresql/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | nest-api: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | container_name: nest-api 8 | restart: always 9 | ports: 10 | - '3000:3000' 11 | depends_on: 12 | - nest-postgres 13 | env_file: 14 | - .env 15 | 16 | nest-postgres: 17 | image: postgres:14 18 | container_name: nest-postgres 19 | restart: always 20 | ports: 21 | - '5432:5432' 22 | env_file: 23 | - .env 24 | volumes: 25 | - nest-postgres:/var/lib/postgresql/data 26 | 27 | volumes: 28 | nest-postgres: 29 | name: nest-postgres-db 30 | -------------------------------------------------------------------------------- /examples/extensions/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get, Param } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | users() { 10 | return this.appService.users(); 11 | } 12 | 13 | @Get('page') 14 | usersPage() { 15 | return this.appService.usersPage(); 16 | } 17 | 18 | /** 19 | * 20 | * http://localhost:3000/ham@burger.dev 21 | * 22 | * @param email 23 | * @returns 24 | */ 25 | @Get(':email') 26 | user(@Param('email') email: string) { 27 | return this.appService.user(email); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /docs/src/icons/prisma.svg: -------------------------------------------------------------------------------- 1 | 2 | 5 | -------------------------------------------------------------------------------- /docs/src/components/ThemeButton.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { Icon } from 'astro-icon'; 3 | --- 4 | 5 | 9 | 10 | 23 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/services/src/prisma/__name@dasherize__.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { <%= classify(name) %>Service } from './<%= dasherize(name) %>.service'; 3 | 4 | describe('<%= classify(name) %>Service', () => { 5 | let service: <%= classify(name) %>Service; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [<%= classify(name) %>Service], 10 | }).compile(); 11 | 12 | service = module.get<<%= classify(name) %>Service>(<%= classify(name) %>Service); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/templates/docker/postgresql/.env: -------------------------------------------------------------------------------- 1 | POSTGRES_USER=prisma 2 | POSTGRES_PASSWORD=topsecret 3 | POSTGRES_DB=mydb 4 | 5 | # See https://www.prisma.io/docs/concepts/database-connectors/postgresql 6 | # Host value is the default container name for postgres - @nest-postgres:5432 7 | # change it when changing the container name 8 | DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@nest-postgres:5432/${POSTGRES_DB}?schema=public 9 | # To have acccess to the database container from your local machine 10 | # use the DATABASE_URL below which replaces nest-postgres (container name) with localhost 11 | #DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?schema=public -------------------------------------------------------------------------------- /tsconfig.schematics.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "tsconfig", 4 | "lib": ["es2018", "dom"], 5 | "declaration": true, 6 | "module": "commonjs", 7 | "moduleResolution": "node", 8 | "noEmitOnError": true, 9 | "noFallthroughCasesInSwitch": true, 10 | "noImplicitAny": true, 11 | "noImplicitThis": true, 12 | "noUnusedParameters": true, 13 | "noUnusedLocals": true, 14 | "rootDir": "schematics/", 15 | "skipDefaultLibCheck": true, 16 | "skipLibCheck": true, 17 | "sourceMap": true, 18 | "strictNullChecks": true, 19 | "target": "es6", 20 | "types": ["node"] 21 | }, 22 | "include": ["schematics/**/*"], 23 | "exclude": ["schematics/*/templates/**/*"] 24 | } 25 | -------------------------------------------------------------------------------- /examples/graphql/src/schema.gql: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------ 2 | # THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY) 3 | # ------------------------------------------------------ 4 | 5 | input CreateUserInput { 6 | email: String! 7 | name: String! 8 | } 9 | 10 | type Mutation { 11 | createUser(createUserInput: CreateUserInput!): User! 12 | removeUser(id: String!): User! 13 | updateUser(updateUserInput: UpdateUserInput!): User! 14 | } 15 | 16 | type Query { 17 | user(id: String!): User! 18 | users: [User!]! 19 | } 20 | 21 | input UpdateUserInput { 22 | email: String 23 | id: String! 24 | name: String 25 | } 26 | 27 | type User { 28 | email: String! 29 | id: String! 30 | name: String 31 | } -------------------------------------------------------------------------------- /schematics/nestjs-prisma/npm-scripts.ts: -------------------------------------------------------------------------------- 1 | export interface NpmScript { 2 | name: string; 3 | command: string; 4 | } 5 | 6 | export const npmScripts: NpmScript[] = [ 7 | { 8 | name: 'migrate:dev', 9 | command: 'npx prisma migrate dev', 10 | }, 11 | { 12 | name: 'migrate:dev:create', 13 | command: 'npx prisma migrate dev --create-only', 14 | }, 15 | { 16 | name: 'migrate:deploy', 17 | command: 'npx prisma migrate deploy', 18 | }, 19 | { 20 | name: 'prisma:generate', 21 | command: 'npx prisma generate', 22 | }, 23 | { 24 | name: 'prisma:studio', 25 | command: 'npx prisma studio', 26 | }, 27 | { 28 | name: 'prisma:seed', 29 | command: 'npx prisma db seed', 30 | }, 31 | ]; 32 | -------------------------------------------------------------------------------- /examples/basics/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/driver/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/fastify/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/extensions/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /examples/extensions/src/query-logging.extension.ts: -------------------------------------------------------------------------------- 1 | import { Logger } from '@nestjs/common'; 2 | import { Prisma } from '@prisma/client'; 3 | 4 | export const queryLoggingExtension = (logger: Logger) => 5 | Prisma.defineExtension({ 6 | name: 'prisma-extension-query-logger', 7 | query: { 8 | $allModels: { 9 | async $allOperations({ operation, model, args, query }) { 10 | const start = performance.now(); 11 | const result = await query(args); 12 | const end = performance.now(); 13 | const time = Math.ceil((end - start) * 100) / 100; 14 | logger.log(`Prisma Query ${model}.${operation} took ${time}ms`); 15 | return result; 16 | }, 17 | }, 18 | }, 19 | }); 20 | -------------------------------------------------------------------------------- /examples/graphql/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { PrismaModule } from 'nestjs-prisma'; 2 | import { Module } from '@nestjs/common'; 3 | import { GraphQLModule } from '@nestjs/graphql'; 4 | import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'; 5 | import { join } from 'path'; 6 | import { UserModule } from './user/user.module'; 7 | 8 | @Module({ 9 | imports: [ 10 | GraphQLModule.forRoot({ 11 | driver: ApolloDriver, 12 | autoSchemaFile: join(process.cwd(), 'src/schema.gql'), 13 | sortSchema: true, 14 | graphiql: true, 15 | }), 16 | PrismaModule.forRoot({ isGlobal: true }), 17 | 18 | UserModule, 19 | ], 20 | controllers: [], 21 | providers: [], 22 | }) 23 | export class AppModule {} 24 | -------------------------------------------------------------------------------- /examples/basics/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /examples/fastify/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /examples/graphql/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /examples/extensions/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /examples/fastify/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Body, Controller, Get, Param, Post } from '@nestjs/common'; 2 | import { User } from '@prisma/client'; 3 | import { AppService } from './app.service'; 4 | import { CreateUserDto } from './dto/create-user.dto'; 5 | 6 | @Controller() 7 | export class AppController { 8 | constructor(private readonly appService: AppService) {} 9 | 10 | @Post() 11 | createUser(@Body() createUserDto: CreateUserDto) { 12 | return this.appService.createUser(createUserDto) 13 | } 14 | 15 | @Get() 16 | users(): Promise { 17 | return this.appService.users(); 18 | } 19 | 20 | @Get(':userId') 21 | user(@Param('userId') userId: string): Promise { 22 | return this.appService.user(userId); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | tsconfigRootDir: __dirname, 6 | sourceType: 'module', 7 | }, 8 | plugins: ['@typescript-eslint/eslint-plugin'], 9 | extends: [ 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:prettier/recommended', 12 | ], 13 | root: true, 14 | env: { 15 | node: true, 16 | jest: true, 17 | }, 18 | ignorePatterns: ['.eslintrc.js'], 19 | rules: { 20 | '@typescript-eslint/interface-name-prefix': 'off', 21 | '@typescript-eslint/explicit-function-return-type': 'off', 22 | '@typescript-eslint/explicit-module-boundary-types': 'off', 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /examples/graphql/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | tsconfigRootDir: __dirname, 6 | sourceType: 'module', 7 | }, 8 | plugins: ['@typescript-eslint/eslint-plugin'], 9 | extends: [ 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:prettier/recommended', 12 | ], 13 | root: true, 14 | env: { 15 | node: true, 16 | jest: true, 17 | }, 18 | ignorePatterns: ['.eslintrc.js'], 19 | rules: { 20 | '@typescript-eslint/interface-name-prefix': 'off', 21 | '@typescript-eslint/explicit-function-return-type': 'off', 22 | '@typescript-eslint/explicit-module-boundary-types': 'off', 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /docs/src/content/docs/custom-prisma-service.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Custom Prisma Service 3 | --- 4 | 5 | Add the flag `--addPrismaService` if you like to generate your own `PrismaService` and `PrismaModule` for further customizations. 6 | 7 | ```bash 8 | nest add nestjs-prisma -- --addPrismaService 9 | ``` 10 | 11 | Add `PrismaModule` to the `imports` section in your `AppModule` or other modules to gain access to `PrismaService`. 12 | 13 | ```ts 14 | import { Module } from '@nestjs/common'; 15 | import { PrismaModule } from './prisma/prisma.module'; 16 | 17 | @Module({ 18 | imports: [PrismaModule], 19 | }) 20 | export class AppModule {} 21 | ``` 22 | 23 | **Note**: It is safe to remove `nestjs-prisma` as dependency otherwise you have two import suggestions for `PrismaService` and `PrismaModule`. 24 | -------------------------------------------------------------------------------- /examples/basics/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | tsconfigRootDir : __dirname, 6 | sourceType: 'module', 7 | }, 8 | plugins: ['@typescript-eslint/eslint-plugin'], 9 | extends: [ 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:prettier/recommended', 12 | ], 13 | root: true, 14 | env: { 15 | node: true, 16 | jest: true, 17 | }, 18 | ignorePatterns: ['.eslintrc.js'], 19 | rules: { 20 | '@typescript-eslint/interface-name-prefix': 'off', 21 | '@typescript-eslint/explicit-function-return-type': 'off', 22 | '@typescript-eslint/explicit-module-boundary-types': 'off', 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /examples/extensions/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | tsconfigRootDir : __dirname, 6 | sourceType: 'module', 7 | }, 8 | plugins: ['@typescript-eslint/eslint-plugin'], 9 | extends: [ 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:prettier/recommended', 12 | ], 13 | root: true, 14 | env: { 15 | node: true, 16 | jest: true, 17 | }, 18 | ignorePatterns: ['.eslintrc.js'], 19 | rules: { 20 | '@typescript-eslint/interface-name-prefix': 'off', 21 | '@typescript-eslint/explicit-function-return-type': 'off', 22 | '@typescript-eslint/explicit-module-boundary-types': 'off', 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /examples/fastify/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | tsconfigRootDir : __dirname, 6 | sourceType: 'module', 7 | }, 8 | plugins: ['@typescript-eslint/eslint-plugin'], 9 | extends: [ 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:prettier/recommended', 12 | ], 13 | root: true, 14 | env: { 15 | node: true, 16 | jest: true, 17 | }, 18 | ignorePatterns: ['.eslintrc.js'], 19 | rules: { 20 | '@typescript-eslint/interface-name-prefix': 'off', 21 | '@typescript-eslint/explicit-function-return-type': 'off', 22 | '@typescript-eslint/explicit-module-boundary-types': 'off', 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /examples/basics/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "nodenext", 4 | "moduleResolution": "nodenext", 5 | "resolvePackageJsonExports": true, 6 | "esModuleInterop": true, 7 | "isolatedModules": true, 8 | "declaration": true, 9 | "removeComments": true, 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "allowSyntheticDefaultImports": true, 13 | "target": "ES2023", 14 | "sourceMap": true, 15 | "outDir": "./dist", 16 | "baseUrl": "./", 17 | "incremental": true, 18 | "skipLibCheck": true, 19 | "strictNullChecks": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "noImplicitAny": false, 22 | "strictBindCallApply": false, 23 | "noFallthroughCasesInSwitch": false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/driver/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "nodenext", 4 | "moduleResolution": "nodenext", 5 | "resolvePackageJsonExports": true, 6 | "esModuleInterop": true, 7 | "isolatedModules": true, 8 | "declaration": true, 9 | "removeComments": true, 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "allowSyntheticDefaultImports": true, 13 | "target": "ES2023", 14 | "sourceMap": true, 15 | "outDir": "./dist", 16 | "baseUrl": "./", 17 | "incremental": true, 18 | "skipLibCheck": true, 19 | "strictNullChecks": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "noImplicitAny": false, 22 | "strictBindCallApply": false, 23 | "noFallthroughCasesInSwitch": false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/fastify/README.md: -------------------------------------------------------------------------------- 1 | # Fastify 2 | 3 | NestJS app with Fastify, Prisma and nestjs-prisma. 4 | 5 | ```sh 6 | npm i 7 | 8 | npm run start:dev 9 | ``` 10 | 11 | Adjust `prisma/schema.prisma` and perform a migration: 12 | 13 | ```sh 14 | npx prisma migrate dev 15 | ``` 16 | 17 | Use `PrismaService` to access the type-safe generated `PrismaClient`. 18 | 19 | ```ts 20 | import { Injectable } from '@nestjs/common'; 21 | import { PrismaService } from 'nestjs-prisma'; 22 | 23 | @Injectable() 24 | export class AppService { 25 | constructor(private prisma: PrismaService) {} 26 | 27 | users() { 28 | return this.prisma.user.findMany(); 29 | } 30 | 31 | user(userId: string) { 32 | return this.prisma.user.findUnique({ 33 | where: { id: userId }, 34 | }); 35 | } 36 | } 37 | ``` 38 | -------------------------------------------------------------------------------- /examples/fastify/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "nodenext", 4 | "moduleResolution": "nodenext", 5 | "resolvePackageJsonExports": true, 6 | "esModuleInterop": true, 7 | "isolatedModules": true, 8 | "declaration": true, 9 | "removeComments": true, 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "allowSyntheticDefaultImports": true, 13 | "target": "ES2023", 14 | "sourceMap": true, 15 | "outDir": "./dist", 16 | "baseUrl": "./", 17 | "incremental": true, 18 | "skipLibCheck": true, 19 | "strictNullChecks": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "noImplicitAny": false, 22 | "strictBindCallApply": false, 23 | "noFallthroughCasesInSwitch": false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/graphql/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "nodenext", 4 | "moduleResolution": "nodenext", 5 | "resolvePackageJsonExports": true, 6 | "esModuleInterop": true, 7 | "isolatedModules": true, 8 | "declaration": true, 9 | "removeComments": true, 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "allowSyntheticDefaultImports": true, 13 | "target": "ES2023", 14 | "sourceMap": true, 15 | "outDir": "./dist", 16 | "baseUrl": "./", 17 | "incremental": true, 18 | "skipLibCheck": true, 19 | "strictNullChecks": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "noImplicitAny": false, 22 | "strictBindCallApply": false, 23 | "noFallthroughCasesInSwitch": false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/driver/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { App } from 'supertest/types'; 5 | import { AppModule } from './../src/app.module'; 6 | 7 | describe('AppController (e2e)', () => { 8 | let app: INestApplication; 9 | 10 | beforeEach(async () => { 11 | const moduleFixture: TestingModule = await Test.createTestingModule({ 12 | imports: [AppModule], 13 | }).compile(); 14 | 15 | app = moduleFixture.createNestApplication(); 16 | await app.init(); 17 | }); 18 | 19 | it('/ (GET)', () => { 20 | return request(app.getHttpServer()) 21 | .get('/') 22 | .expect(200) 23 | .expect('Hello World!'); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /examples/extensions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "nodenext", 4 | "moduleResolution": "nodenext", 5 | "resolvePackageJsonExports": true, 6 | "esModuleInterop": true, 7 | "isolatedModules": true, 8 | "declaration": true, 9 | "removeComments": true, 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "allowSyntheticDefaultImports": true, 13 | "target": "ES2023", 14 | "sourceMap": true, 15 | "outDir": "./dist", 16 | "baseUrl": "./", 17 | "incremental": true, 18 | "skipLibCheck": true, 19 | "strictNullChecks": true, 20 | "forceConsistentCasingInFileNames": true, 21 | "noImplicitAny": false, 22 | "strictBindCallApply": false, 23 | "noFallthroughCasesInSwitch": false 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /docs/src/components/TableOfContents.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import type { MarkdownHeading } from 'astro'; 3 | 4 | export interface Props { 5 | headings: MarkdownHeading[]; 6 | } 7 | 8 | const { headings } = Astro.props; 9 | --- 10 | 11 |
12 |
On this page
13 |
    14 | { 15 | headings 16 | .filter(({ depth }) => depth === 2 || depth === 3) 17 | .map((heading) => ( 18 |
  • 19 | 23 | {heading.text} 24 | 25 |
  • 26 | )) 27 | } 28 |
29 |
30 | -------------------------------------------------------------------------------- /docs/src/content/docs/installation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Installation 3 | --- 4 | 5 | ## Automatic Install 6 | 7 | Use the [nest add](/docs/schematics) command to automatically setup the library, Prisma and Docker (optionally): 8 | 9 | ```sh 10 | nest add nestjs-prisma 11 | ``` 12 | 13 | ## Manual Install 14 | 15 | Add `nestjs-prisma` library to your [NestJS application](https://docs.nestjs.com/#installation): 16 | 17 | ```sh 18 | # npm 19 | npm install nestjs-prisma 20 | 21 | # yarn 22 | yarn add nestjs-prisma 23 | ``` 24 | 25 | Furthermore, setup [Prisma](https://www.prisma.io/docs/getting-started/setup-prisma/add-to-existing-project/relational-databases-typescript-postgres#set-up-prisma) in your NestJS application, if you haven't already. 26 | 27 | ```sh 28 | npm i -D prisma 29 | npm install @prisma/client 30 | 31 | npx prisma init 32 | ``` 33 | -------------------------------------------------------------------------------- /lib/prisma.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable, OnModuleInit, Optional } from '@nestjs/common'; 2 | import { Prisma, PrismaClient } from '@prisma/client'; 3 | import { PrismaServiceOptions } from './interfaces'; 4 | import { PRISMA_SERVICE_OPTIONS } from './prisma.constants'; 5 | 6 | @Injectable() 7 | export class PrismaService 8 | extends PrismaClient< 9 | Prisma.PrismaClientOptions, 10 | 'query' | 'info' | 'warn' | 'error' 11 | > 12 | implements OnModuleInit 13 | { 14 | constructor( 15 | @Optional() 16 | @Inject(PRISMA_SERVICE_OPTIONS) 17 | private readonly prismaServiceOptions: PrismaServiceOptions = {}, 18 | ) { 19 | super(prismaServiceOptions.prismaOptions); 20 | } 21 | 22 | async onModuleInit() { 23 | if (this.prismaServiceOptions.explicitConnect) { 24 | await this.$connect(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/driver/src/generated/prisma/browser.ts: -------------------------------------------------------------------------------- 1 | 2 | /* !!! This is code generated by Prisma. Do not edit directly. !!! */ 3 | /* eslint-disable */ 4 | // biome-ignore-all lint: generated file 5 | // @ts-nocheck 6 | /* 7 | * This file should be your main import to use Prisma-related types and utilities in a browser. 8 | * Use it to get access to models, enums, and input types. 9 | * 10 | * This file does not contain a `PrismaClient` class, nor several other helpers that are intended as server-side only. 11 | * See `client.ts` for the standard, server-side entry point. 12 | * 13 | * 🟢 You can import this file directly. 14 | */ 15 | 16 | import * as Prisma from './internal/prismaNamespaceBrowser.js' 17 | export { Prisma } 18 | export * as $Enums from './enums.js' 19 | export * from './enums.js'; 20 | /** 21 | * Model User 22 | * 23 | */ 24 | export type User = Prisma.UserModel 25 | -------------------------------------------------------------------------------- /examples/fastify/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { PrismaService } from 'nestjs-prisma'; 3 | import { CreateUserDto } from './dto/create-user.dto'; 4 | 5 | @Injectable() 6 | export class AppService { 7 | constructor(private prisma: PrismaService) {} 8 | 9 | createUser(createUserDto: CreateUserDto) { 10 | return this.prisma.user.create({ data: createUserDto }); 11 | } 12 | 13 | users() { 14 | return this.prisma.user.findMany(); 15 | } 16 | 17 | user(userId: string) { 18 | // returns `null` if not found 19 | // return this.prisma.user.findUnique({ 20 | // where: { id: userId }, 21 | // }); 22 | // throws `Prisma.NotFoundError` if not found, use `PrismaClientExceptionFilter` to catch the exception 23 | return this.prisma.user.findUniqueOrThrow({ 24 | where: { id: userId }, 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /docs/src/icons/github.svg: -------------------------------------------------------------------------------- 1 | 3 | 5 | 6 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Build 5 | 6 | on: 7 | push: 8 | branches: [ main ] 9 | pull_request: 10 | branches: [ main ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [20, 22] 20 | 21 | steps: 22 | - uses: actions/checkout@v4 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | cache: 'npm' 28 | - run: npm install 29 | - run: npx prisma generate 30 | - run: npm run lint 31 | - run: npm run build 32 | -------------------------------------------------------------------------------- /examples/basics/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { APP_FILTER, HttpAdapterHost } from '@nestjs/core'; 3 | import { 4 | PrismaClientExceptionFilter, 5 | PrismaModule, 6 | } from 'nestjs-prisma'; 7 | import { AppController } from './app.controller'; 8 | import { AppService } from './app.service'; 9 | 10 | @Module({ 11 | imports: [ 12 | PrismaModule.forRoot({ 13 | prismaServiceOptions: {}, 14 | }), 15 | ], 16 | controllers: [AppController], 17 | providers: [ 18 | AppService, 19 | // register filter here or in main.ts 20 | // { 21 | // provide: APP_FILTER, 22 | // useFactory: ({ httpAdapter }: HttpAdapterHost) => { 23 | // return new PrismaClientExceptionFilter(httpAdapter); 24 | // }, 25 | // inject: [HttpAdapterHost], 26 | // }, 27 | // or 28 | // providePrismaClientExceptionFilter() 29 | ], 30 | }) 31 | export class AppModule {} 32 | -------------------------------------------------------------------------------- /examples/graphql/src/user/user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { CreateUserInput } from './dto/create-user.input'; 3 | import { UpdateUserInput } from './dto/update-user.input'; 4 | import { PrismaService } from 'nestjs-prisma'; 5 | 6 | @Injectable() 7 | export class UserService { 8 | constructor(private readonly prisma: PrismaService) {} 9 | 10 | create(createUserInput: CreateUserInput) { 11 | return this.prisma.user.create({ data: createUserInput }); 12 | } 13 | 14 | findAll() { 15 | return this.prisma.user.findMany(); 16 | } 17 | 18 | findOne(id: string) { 19 | return this.prisma.user.findUniqueOrThrow({ where: { id } }); 20 | } 21 | 22 | update(id: string, updateUserInput: UpdateUserInput) { 23 | return this.prisma.user.update({ where: { id }, data: updateUserInput }); 24 | } 25 | 26 | remove(id: string) { 27 | return this.prisma.user.delete({ where: { id } }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/basics/README.md: -------------------------------------------------------------------------------- 1 | # Basics 2 | 3 | NestJS app with Express, Prisma and nestjs-prisma. 4 | 5 | Adjust `prisma/schema.prisma` and perform a migration: 6 | 7 | ```sh 8 | npx prisma migrate dev 9 | ``` 10 | 11 | Seed the example database: 12 | 13 | ```sh 14 | npx prisma db seed 15 | ``` 16 | 17 | Start the Nest app and open [localhost:3000](http://localhost:3000). 18 | 19 | ```sh 20 | npm i 21 | 22 | npm run start:dev 23 | ``` 24 | 25 | Use `PrismaService` to access the type-safe generated `PrismaClient`. 26 | 27 | ```ts 28 | import { Injectable } from '@nestjs/common'; 29 | import { PrismaService } from 'nestjs-prisma'; 30 | 31 | @Injectable() 32 | export class AppService { 33 | constructor(private prisma: PrismaService) {} 34 | 35 | users() { 36 | return this.prisma.user.findMany(); 37 | } 38 | 39 | user(userId: string) { 40 | return this.prisma.user.findUnique({ 41 | where: { id: userId }, 42 | }); 43 | } 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /examples/driver/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | /build 5 | 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | pnpm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | lerna-debug.log* 14 | 15 | # OS 16 | .DS_Store 17 | 18 | # Tests 19 | /coverage 20 | /.nyc_output 21 | 22 | # IDEs and editors 23 | /.idea 24 | .project 25 | .classpath 26 | .c9/ 27 | *.launch 28 | .settings/ 29 | *.sublime-workspace 30 | 31 | # IDE - VSCode 32 | .vscode/* 33 | !.vscode/settings.json 34 | !.vscode/tasks.json 35 | !.vscode/launch.json 36 | !.vscode/extensions.json 37 | 38 | # dotenv environment variable files 39 | .env 40 | .env.development.local 41 | .env.test.local 42 | .env.production.local 43 | .env.local 44 | 45 | # temp directory 46 | .temp 47 | .tmp 48 | 49 | # Runtime data 50 | pids 51 | *.pid 52 | *.seed 53 | *.pid.lock 54 | 55 | # Diagnostic reports (https://nodejs.org/api/report.html) 56 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 57 | 58 | # prisma 59 | prisma/dev.db* -------------------------------------------------------------------------------- /examples/driver/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import eslint from '@eslint/js'; 3 | import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; 4 | import globals from 'globals'; 5 | import tseslint from 'typescript-eslint'; 6 | 7 | export default tseslint.config( 8 | { 9 | ignores: ['eslint.config.mjs'], 10 | }, 11 | eslint.configs.recommended, 12 | ...tseslint.configs.recommendedTypeChecked, 13 | eslintPluginPrettierRecommended, 14 | { 15 | languageOptions: { 16 | globals: { 17 | ...globals.node, 18 | ...globals.jest, 19 | }, 20 | sourceType: 'commonjs', 21 | parserOptions: { 22 | projectService: true, 23 | tsconfigRootDir: import.meta.dirname, 24 | }, 25 | }, 26 | }, 27 | { 28 | rules: { 29 | '@typescript-eslint/no-explicit-any': 'off', 30 | '@typescript-eslint/no-floating-promises': 'warn', 31 | '@typescript-eslint/no-unsafe-argument': 'warn' 32 | }, 33 | }, 34 | ); -------------------------------------------------------------------------------- /examples/extensions/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Inject, Injectable } from '@nestjs/common'; 2 | import { CustomPrismaService } from 'nestjs-prisma'; 3 | import { type ExtendedPrismaClient } from './prisma.extension'; 4 | 5 | @Injectable() 6 | export class AppService { 7 | constructor( 8 | // ✅ use `ExtendedPrismaClient` from extension for correct type-safety 9 | @Inject('PrismaService') 10 | private prismaService: CustomPrismaService, 11 | ) {} 12 | 13 | users() { 14 | return this.prismaService.client.user.findMany(); 15 | } 16 | 17 | async usersPage() { 18 | const [users, meta] = await this.prismaService.client.user 19 | .paginate() 20 | .withPages({ 21 | limit: 10, 22 | page: 1, 23 | includePageCount: true, 24 | }); 25 | 26 | return { 27 | users, 28 | meta, 29 | }; 30 | } 31 | 32 | user(email: string) { 33 | // 🦾 use new `findByEmail` 34 | return this.prismaService.client.user.findByEmail(email); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/schema.ts: -------------------------------------------------------------------------------- 1 | export interface Schema { 2 | /** 3 | * Create a Prisma service extending the Prisma Client and module. 4 | */ 5 | addPrismaService?: boolean; 6 | 7 | /** 8 | * Create a Dockerfile and docker-compose.yaml. 9 | */ 10 | addDocker?: boolean; 11 | 12 | /** 13 | * Select a datasource provider to pass to `prisma init`. 14 | */ 15 | datasourceProvider: DatasourceProvider; 16 | 17 | /** 18 | * Node version for the builder and runner image. 19 | */ 20 | dockerNodeImageVersion: string; 21 | 22 | /** 23 | * The name for the Prisma Service extending the Prisma Client. 24 | */ 25 | name: string; 26 | 27 | /** 28 | * Prisma version. 29 | */ 30 | prismaVersion: string; 31 | 32 | /** 33 | * Skip installing dependency packages. 34 | */ 35 | skipInstall?: boolean; 36 | 37 | /** 38 | * Skip initializing Prisma. 39 | */ 40 | skipPrismaInit?: boolean; 41 | } 42 | 43 | export type DatasourceProvider = 44 | | 'postgresql' 45 | | 'mysql' 46 | | 'sqlite' 47 | | 'sqlserver' 48 | | 'mongodb'; 49 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/utils/get-latest-dependency-version.ts: -------------------------------------------------------------------------------- 1 | import { get } from 'http'; 2 | 3 | export interface NodePackage { 4 | name: string; 5 | version: string; 6 | } 7 | 8 | export function getLatestDependencyVersion( 9 | packageName: string, 10 | ): Promise { 11 | const DEFAULT_VERSION = 'latest'; 12 | 13 | return new Promise((resolve) => { 14 | return get(`http://registry.npmjs.org/${packageName}`, (res) => { 15 | let rawData = ''; 16 | res.on('data', (chunk) => (rawData += chunk)); 17 | res.on('end', () => { 18 | try { 19 | const response = JSON.parse(rawData); 20 | const version = (response && response['dist-tags']) || {}; 21 | resolve(buildPackage(packageName, version.latest)); 22 | } catch (e) { 23 | resolve(buildPackage(packageName)); 24 | } 25 | }); 26 | }).on('error', () => resolve(buildPackage(packageName))); 27 | }); 28 | 29 | function buildPackage( 30 | name: string, 31 | version: string = DEFAULT_VERSION, 32 | ): NodePackage { 33 | return { name, version }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /docs/src/pages/404.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from '../layouts/Base.astro'; 3 | --- 4 | 5 | 6 |
7 |
8 |

11 | 404 12 |

13 |

16 | Page not found 17 |

18 |

19 | Sorry, we couldn't find the page you're looking for. 20 |

21 | 29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Marc Stammerjohann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/src/pages/docs/examples.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import CustomDoc from '../../layouts/CustomDoc.astro'; 3 | import { examples } from '../../config'; 4 | import { Icon } from 'astro-icon'; 5 | --- 6 | 7 | 11 | 32 | 33 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@example/basics", 3 | "type": "module", 4 | "version": "0.0.1", 5 | "private": true, 6 | "scripts": { 7 | "dev": "astro dev", 8 | "start": "astro dev", 9 | "build": "astro build", 10 | "preview": "astro preview", 11 | "astro": "astro", 12 | "format": "prettier --write ." 13 | }, 14 | "dependencies": { 15 | "@astrojs/alpinejs": "^0.4.0", 16 | "@astrojs/react": "^3.0.9", 17 | "@astrojs/sitemap": "^3.0.5", 18 | "@astrojs/tailwind": "^5.1.0", 19 | "@docsearch/react": "^3.3.4", 20 | "alpinejs": "^3.13.5", 21 | "astro": "^4.3.1", 22 | "astro-icon": "^0.8.2", 23 | "astro-robots-txt": "^1.0.0", 24 | "astro-seo": "^0.8.0", 25 | "inter-ui": "^3.19.3", 26 | "react": "^18.2.0", 27 | "react-dom": "^18.2.0", 28 | "tailwindcss": "^3.4.1" 29 | }, 30 | "devDependencies": { 31 | "@tailwindcss/typography": "^0.5.10", 32 | "@types/alpinejs": "^3.13.6", 33 | "@types/react": "^18.2.0", 34 | "@types/react-dom": "^18.2.1", 35 | "prettier": "^3.2.4", 36 | "prettier-plugin-astro": "^0.13.0", 37 | "prettier-plugin-tailwindcss": "^0.5.11" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /schematics/prisma-init/index.ts: -------------------------------------------------------------------------------- 1 | import { SchematicContext, Tree } from '@angular-devkit/schematics'; 2 | import { exec } from 'child_process'; 3 | import { Observable } from 'rxjs'; 4 | import { DatasourceProvider } from './../nestjs-prisma/schema'; 5 | 6 | interface InitOptions { 7 | datasource: DatasourceProvider; 8 | } 9 | 10 | // You don't have to export the function as default. You can also have more than one rule factory 11 | // per file. 12 | export function prismaInit(_options: InitOptions) { 13 | return (host: Tree, _context: SchematicContext) => { 14 | _context.logger.info( 15 | `✅️ Initialized Prisma - Datasource ${_options.datasource}`, 16 | ); 17 | return new Observable((subscriber) => { 18 | const child = exec( 19 | `npx prisma init --datasource-provider ${_options.datasource}`, 20 | ); 21 | child.on('error', (error) => { 22 | subscriber.error(error); 23 | }); 24 | child.on('close', () => { 25 | subscriber.next(host); 26 | subscriber.complete(); 27 | }); 28 | return () => { 29 | child.kill(); 30 | return host; 31 | }; 32 | }); 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /docs/src/components/Search.css: -------------------------------------------------------------------------------- 1 | /** Style Algolia */ 2 | /* TODO use tailwind css styles and consider dark/light */ 3 | :root { 4 | --docsearch-primary-color: theme(colors.violet.500); 5 | } 6 | 7 | :root.dark { 8 | --docsearch-modal-background: theme(colors.gray.900); 9 | --docsearch-footer-background: theme(colors.gray.800); 10 | --docsearch-modal-shadow: theme('boxShadow.lg'); 11 | --docsearch-footer-shadow: theme('boxShadow.lg'); 12 | 13 | /* search input */ 14 | --docsearch-searchbox-focus-background: theme(colors.gray.800); 15 | --docsearch-text-color: theme(colors.gray.100); 16 | 17 | /* search item */ 18 | --docsearch-hit-background: theme(colors.gray.800); 19 | --docsearch-hit-color: theme(colors.gray.300); 20 | } 21 | 22 | /* ------------------------------------------------------------ *\ 23 | DocSearch (Algolia) 24 | \* ------------------------------------------------------------ */ 25 | 26 | .DocSearch-Modal .DocSearch-Hit a { 27 | box-shadow: none; 28 | border: 1px solid var(--theme-accent); 29 | } 30 | 31 | .DocSearch-Commands { 32 | @apply hidden; 33 | } 34 | 35 | .DocSearch-NoResults .DocSearch-Screen-Icon { 36 | @apply hidden; 37 | } 38 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | # Simple workflow for deploying static content to GitHub Pages 2 | name: Deploy Docs 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: [ main ] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | # Allow one concurrent deployment 19 | concurrency: 20 | group: "pages" 21 | cancel-in-progress: true 22 | 23 | jobs: 24 | # Single deploy job since we're just deploying 25 | deploy: 26 | environment: 27 | name: github-pages 28 | url: ${{ steps.deployment.outputs.page_url }} 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v4 33 | - name: Install, build, and upload your site output 34 | uses: withastro/action@v3 35 | with: 36 | path: ./docs 37 | # package-manager: npm 38 | - name: Deploy to GitHub Pages 39 | id: deployment 40 | uses: actions/deploy-pages@v4 41 | -------------------------------------------------------------------------------- /examples/graphql/src/user/user.resolver.ts: -------------------------------------------------------------------------------- 1 | import { Resolver, Query, Mutation, Args } from '@nestjs/graphql'; 2 | import { UserService } from './user.service'; 3 | import { User } from './entities/user.entity'; 4 | import { CreateUserInput } from './dto/create-user.input'; 5 | import { UpdateUserInput } from './dto/update-user.input'; 6 | 7 | @Resolver(() => User) 8 | export class UserResolver { 9 | constructor(private readonly userService: UserService) {} 10 | 11 | @Mutation(() => User) 12 | createUser(@Args('createUserInput') createUserInput: CreateUserInput) { 13 | return this.userService.create(createUserInput); 14 | } 15 | 16 | @Query(() => [User], { name: 'users' }) 17 | findAll() { 18 | return this.userService.findAll(); 19 | } 20 | 21 | @Query(() => User, { name: 'user' }) 22 | findOne(@Args('id') id: string) { 23 | return this.userService.findOne(id); 24 | } 25 | 26 | @Mutation(() => User) 27 | updateUser(@Args('updateUserInput') updateUserInput: UpdateUserInput) { 28 | return this.userService.update(updateUserInput.id, updateUserInput); 29 | } 30 | 31 | @Mutation(() => User) 32 | removeUser(@Args('id') id: string) { 33 | return this.userService.remove(id); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /docs/src/content/docs/prisma-logging.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Prisma Event-based logging 3 | --- 4 | 5 | To use Prisma [event-based logging](https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/logging#event-based-logging) first specify the log level in `prismaOptions` of your `PrismaModule`: 6 | 7 | ```ts 8 | import { Module } from '@nestjs/common'; 9 | import { PrismaModule } from 'nestjs-prisma'; 10 | 11 | @Module({ 12 | imports: [ 13 | PrismaModule.forRoot({ 14 | prismaServiceOptions: { 15 | prismaOptions: { 16 | log: [ 17 | { 18 | emit: 'event', 19 | level: 'query', 20 | }, 21 | ], 22 | }, 23 | }, 24 | }), 25 | ], 26 | }) 27 | export class AppModule {} 28 | ``` 29 | 30 | Now use `$on()` via the `PrismaService` in `main.ts` to subscribe to all events. 31 | 32 | ```ts 33 | // main.ts 34 | import { NestFactory } from '@nestjs/core'; 35 | import { AppModule } from './app.module'; 36 | import { PrismaService } from 'nestjs-prisma'; 37 | 38 | async function bootstrap() { 39 | const app = await NestFactory.create(AppModule); 40 | 41 | // log query events 42 | const prismaService: PrismaService = app.get(PrismaService); 43 | prismaService.$on('query', (event) => { 44 | console.log(event); 45 | }); 46 | 47 | await app.listen(process.env.PORT || 3000); 48 | } 49 | bootstrap(); 50 | ``` 51 | -------------------------------------------------------------------------------- /docs/src/components/PrevNextNavigation.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import { navigation } from '../config'; 3 | 4 | const currentPage = Astro.url.pathname; 5 | const currentPageMatch = currentPage.endsWith('/') 6 | ? currentPage.slice(0, -1) 7 | : currentPage.slice(0); 8 | const links = navigation.flatMap((section) => section.links); 9 | const linkIndex = links.findIndex((link) => link.link === currentPageMatch); 10 | const previousPage = links[linkIndex - 1]; 11 | const nextPage = links[linkIndex + 1]; 12 | --- 13 | 14 |
15 | { 16 | previousPage && ( 17 |
18 |

Previous

19 | 27 |
28 | ) 29 | } 30 | 31 | { 32 | nextPage && ( 33 |
34 |

Next

35 | 43 |
44 | ) 45 | } 46 |
47 | -------------------------------------------------------------------------------- /examples/extensions/src/prisma.extension.ts: -------------------------------------------------------------------------------- 1 | import { Prisma, PrismaClient } from '@prisma/client'; 2 | import pagination from 'prisma-extension-pagination'; 3 | // used for Read Replicas example 4 | import { readReplicas } from '@prisma/extension-read-replicas'; 5 | import { Logger } from '@nestjs/common'; 6 | import { queryLoggingExtension } from './query-logging.extension'; 7 | 8 | const logger = new Logger('PrismaClient'); 9 | 10 | export const extendedPrismaClient = new PrismaClient< 11 | Prisma.PrismaClientOptions, 12 | 'query' | 'info' | 'warn' | 'error' 13 | >({ 14 | log: [ 15 | { level: 'query', emit: 'event' }, 16 | { level: 'info', emit: 'event' }, 17 | { level: 'warn', emit: 'event' }, 18 | { level: 'error', emit: 'event' }, 19 | ], 20 | }) 21 | .$extends(queryLoggingExtension(logger)) 22 | .$extends({ 23 | model: { 24 | user: { 25 | findByEmail: async (email: string) => { 26 | console.log('extension findByEmail'); 27 | return extendedPrismaClient.user.findFirstOrThrow({ 28 | where: { email }, 29 | }); 30 | }, 31 | }, 32 | }, 33 | }) 34 | .$extends(pagination()); 35 | // Read Replicas example, change datasource prodiver (prisma/schema.prisma) to a supported database 36 | // More details in the blog - https://www.prisma.io/blog/read-replicas-prisma-client-extension-f66prwk56wow 37 | // .$extends( 38 | // readReplicas({ 39 | // url: 'postgres://localhost:5432/prisma', 40 | // }), 41 | // ); 42 | 43 | export type ExtendedPrismaClient = typeof extendedPrismaClient; 44 | -------------------------------------------------------------------------------- /docs/tailwind.config.cjs: -------------------------------------------------------------------------------- 1 | const plugin = require('tailwindcss/plugin'); 2 | const defaultTheme = require('tailwindcss/defaultTheme'); 3 | 4 | /** @type {import('tailwindcss').Config} */ 5 | module.exports = { 6 | content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], 7 | darkMode: 'class', 8 | theme: { 9 | extend: { 10 | fontFamily: { 11 | sans: ['inter', ...defaultTheme.fontFamily.sans], 12 | }, 13 | typography: ({ theme }) => ({ 14 | DEFAULT: { 15 | css: { 16 | code: { 17 | color: '#FFA657', 18 | backgroundColor: '#0d1117', 19 | padding: '0.125rem 0.25rem', 20 | borderRadius: theme('borderRadius.md'), 21 | }, 22 | 'code::before': { 23 | content: '', 24 | }, 25 | 'code::after': { 26 | content: '', 27 | }, 28 | 'blockquote p:first-of-type::before': { 29 | content: '', 30 | }, 31 | 'blockquote p:last-of-type::after': { 32 | content: '', 33 | }, 34 | 'blockquote code': { 35 | color: '#FFA657', 36 | }, 37 | }, 38 | }, 39 | }), 40 | }, 41 | }, 42 | plugins: [ 43 | require('@tailwindcss/typography'), 44 | plugin(({ addVariant }) => { 45 | addVariant('scrollbar', '&::-webkit-scrollbar'); 46 | addVariant('scrollbar-track', '&::-webkit-scrollbar-track'); 47 | addVariant('scrollbar-thumb', '&::-webkit-scrollbar-thumb'); 48 | }), 49 | ], 50 | }; 51 | -------------------------------------------------------------------------------- /lib/interfaces/prisma-module-options.interface.ts: -------------------------------------------------------------------------------- 1 | import { ModuleMetadata, Type } from '@nestjs/common'; 2 | import { Prisma } from '@prisma/client'; 3 | 4 | export interface PrismaModuleOptions { 5 | /** 6 | * If "true", registers `PrismaModule` as a global module. 7 | * See: https://docs.nestjs.com/modules#global-modules 8 | */ 9 | isGlobal?: boolean; 10 | 11 | prismaServiceOptions?: PrismaServiceOptions; 12 | } 13 | 14 | export interface PrismaServiceOptions { 15 | /** 16 | * Pass options directly to the `PrismaClient`. 17 | * See: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference/#prismaclient 18 | */ 19 | prismaOptions?: Prisma.PrismaClientOptions; 20 | 21 | /** 22 | * If "true", `PrismaClient` explicitly creates a connection pool and your first query will respond instantly. 23 | * 24 | * For most use cases the lazy connect behavior of `PrismaClient` will do. The first query of `PrismaClient` creates the connection pool. 25 | * See: https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/connection-management 26 | */ 27 | explicitConnect?: boolean; 28 | } 29 | 30 | export interface PrismaOptionsFactory { 31 | createPrismaOptions(): Promise | PrismaServiceOptions; 32 | } 33 | 34 | export interface PrismaModuleAsyncOptions 35 | extends Pick { 36 | isGlobal?: boolean; 37 | useExisting?: Type; 38 | useClass?: Type; 39 | useFactory?: ( 40 | ...args: any[] 41 | ) => Promise | PrismaServiceOptions; 42 | inject?: any[]; 43 | } 44 | -------------------------------------------------------------------------------- /examples/extensions/README.md: -------------------------------------------------------------------------------- 1 | # PrismaClient Extension 2 | 3 | NestJS app with PrismaClient Extension and nestjs-prisma. 4 | 5 | Adjust `prisma/schema.prisma` and perform a migration: 6 | 7 | ```sh 8 | npx prisma migrate dev 9 | ``` 10 | 11 | Seed the example database: 12 | 13 | ```sh 14 | npx prisma db seed 15 | ``` 16 | 17 | Start the Nest app and open [localhost:3000](http://localhost:3000). 18 | 19 | ```sh 20 | npm i 21 | 22 | npm run start:dev 23 | ``` 24 | 25 | Use `CustomPrismaService` to access the type-safe generated `PrismaClient` and use the extensions. 26 | 27 | ```ts 28 | import { Inject, Injectable } from '@nestjs/common'; 29 | import { CustomPrismaService } from 'nestjs-prisma'; 30 | import { type ExtendedPrismaClient } from './prisma.extension'; 31 | 32 | @Injectable() 33 | export class AppService { 34 | constructor( 35 | // ✅ use `ExtendedPrismaClient` from extension for correct type-safety 36 | @Inject('PrismaService') 37 | private prismaService: CustomPrismaService, 38 | ) {} 39 | 40 | users() { 41 | return this.prismaService.client.user.findMany(); 42 | } 43 | 44 | async usersPage() { 45 | const [users, meta] = await this.prismaService.client.user 46 | .paginate() 47 | .withPages({ 48 | limit: 10, 49 | page: 1, 50 | includePageCount: true, 51 | }); 52 | 53 | return { 54 | users, 55 | meta, 56 | }; 57 | } 58 | 59 | user(email: string) { 60 | // 🦾 use new `findByEmail` 61 | return this.prismaService.client.user.findByEmail(email); 62 | } 63 | } 64 | ``` 65 | 66 | Open users page endpoint [localhost:3000/page](http://localhost:3000/page). -------------------------------------------------------------------------------- /examples/driver/src/generated/prisma/client.ts: -------------------------------------------------------------------------------- 1 | 2 | /* !!! This is code generated by Prisma. Do not edit directly. !!! */ 3 | /* eslint-disable */ 4 | // biome-ignore-all lint: generated file 5 | // @ts-nocheck 6 | /* 7 | * This file should be your main import to use Prisma. Through it you get access to all the models, enums, and input types. 8 | * If you're looking for something you can import in the client-side of your application, please refer to the `browser.ts` file instead. 9 | * 10 | * 🟢 You can import this file directly. 11 | */ 12 | 13 | import * as process from 'node:process' 14 | import * as path from 'node:path' 15 | 16 | import * as runtime from "@prisma/client/runtime/client" 17 | import * as $Enums from "./enums.js" 18 | import * as $Class from "./internal/class.js" 19 | import * as Prisma from "./internal/prismaNamespace.js" 20 | 21 | export * as $Enums from './enums.js' 22 | export * from "./enums.js" 23 | /** 24 | * ## Prisma Client 25 | * 26 | * Type-safe database client for TypeScript 27 | * @example 28 | * ``` 29 | * const prisma = new PrismaClient() 30 | * // Fetch zero or more Users 31 | * const users = await prisma.user.findMany() 32 | * ``` 33 | * 34 | * Read more in our [docs](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client). 35 | */ 36 | export const PrismaClient = $Class.getPrismaClientClass() 37 | export type PrismaClient = $Class.PrismaClient 38 | export { Prisma } 39 | 40 | /** 41 | * Model User 42 | * 43 | */ 44 | export type User = Prisma.UserModel 45 | -------------------------------------------------------------------------------- /schematics/nestjs-prisma/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "$id": "NestPrismaSchematics", 4 | "title": "Prisma Support Schema", 5 | "type": "object", 6 | "description": "Add Prisma support to the NestJS application", 7 | "properties": { 8 | "datasourceProvider": { 9 | "type": "string", 10 | "default": "postgresql", 11 | "description": "Specifies the datasource provider for prisma init and docker.", 12 | "enum": ["postgresql", "mysql", "sqlite", "sqlserver", "mongodb"], 13 | "x-prompt": "Which datasource provider do you want to use for `prisma init`?" 14 | }, 15 | "addDocker": { 16 | "type": "boolean", 17 | "description": "Create a Dockerfile and docker-compose.yaml.", 18 | "x-prompt": "Do you like to Dockerize your application? (Supports postgresql and mysql)" 19 | }, 20 | "dockerNodeImageVersion": { 21 | "type": "string", 22 | "description": "Node version for the builder and runner image.", 23 | "default": "16" 24 | }, 25 | "addPrismaService": { 26 | "type": "boolean", 27 | "description": "Create a Prisma service extending the Prisma Client and module." 28 | }, 29 | "name": { 30 | "type": "string", 31 | "description": "The name for the Prisma service extending the Prisma Client and module.", 32 | "default": "Prisma" 33 | }, 34 | "prismaVersion": { 35 | "type": "string", 36 | "description": "The Prisma version to be installed.", 37 | "default": "latest" 38 | }, 39 | "skipInstall": { 40 | "type": "boolean", 41 | "description": "Skip installing dependency packages.", 42 | "default": false 43 | }, 44 | "skipPrismaInit": { 45 | "type": "boolean", 46 | "description": "Skip initializing Prisma.", 47 | "default": false 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/custom/custom-prisma-options.ts: -------------------------------------------------------------------------------- 1 | import { ModuleMetadata, Type } from '@nestjs/common'; 2 | 3 | export type PrismaClientLike = { 4 | /** 5 | * Connect with the database 6 | */ 7 | $connect(): Promise; 8 | 9 | /** 10 | * Disconnect from the database 11 | */ 12 | $disconnect(): Promise; 13 | }; 14 | 15 | export interface CustomPrismaModuleOptions { 16 | /** 17 | * If "true", registers `PrismaModule` as a global module. 18 | * See: https://docs.nestjs.com/modules#global-modules 19 | */ 20 | isGlobal?: boolean; 21 | 22 | /** 23 | * Choose a name to inject the custom prisma service with. 24 | * 25 | * @example 26 | * name = 'PrismaServiceAuth' 27 | * 28 | * constructor( 29 | * @Inject('PrismaServiceAuth') 30 | * private prismaAuth: CustomPrismaService, 31 | * ){} 32 | * 33 | */ 34 | name: string; 35 | 36 | /** 37 | * Pass an instance of your PrismaClient, useful when you specified a custom output path for your PrismaClient. 38 | * 39 | * @example client = new PrismaClient() 40 | */ 41 | client: Client; 42 | } 43 | 44 | export interface CustomPrismaClientFactory { 45 | createPrismaClient(): Promise | Client; 46 | } 47 | 48 | export interface CustomPrismaModuleAsyncOptions 49 | extends Pick { 50 | isGlobal?: boolean; 51 | 52 | /** 53 | * Choose a name to inject the custom prisma service with. 54 | * 55 | * @example 56 | * name = 'PrismaServiceAuth' 57 | * 58 | * constructor( 59 | * @Inject('PrismaServiceAuth') 60 | * private prismaAuth: CustomPrismaService, 61 | * ){} 62 | * 63 | */ 64 | name: string; 65 | 66 | useClass?: Type>; 67 | 68 | useFactory?: (...args: any[]) => Promise | Client; 69 | inject?: any[]; 70 | } 71 | -------------------------------------------------------------------------------- /docs/src/content/docs/basic-usage.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Basic Usage 3 | --- 4 | 5 | ## Prisma schema 6 | 7 | `nestjs-prisma` requires the Prisma Client to be generated to the default output location (`./node_modules/.prisma/client`). The client will be imported from `@prisma/client`. 8 | 9 | ```prisma 10 | // prisma/schema.prisma 11 | datasource db { 12 | provider = "sqlite" 13 | url = env("DATABASE_URL") 14 | } 15 | 16 | generator client { 17 | provider = "prisma-client-js" 18 | } 19 | 20 | model User { 21 | id Int @id @default(autoincrement()) 22 | email String @unique 23 | name String? 24 | } 25 | ``` 26 | 27 | If you like to choose a **different** output location or want to use **multiple** Prisma Client, you can [customize the Prisma Client location](/docs/custom-prisma-client-location). 28 | 29 | ## PrismaModule and PrismaService 30 | 31 | Add `PrismaModule` to the `imports` section in your `AppModule` or other modules to gain access to `PrismaService`. 32 | 33 | ```ts 34 | import { Module } from '@nestjs/common'; 35 | import { PrismaModule } from 'nestjs-prisma'; 36 | 37 | @Module({ 38 | imports: [PrismaModule], 39 | }) 40 | export class AppModule {} 41 | ``` 42 | 43 | [Configure](/docs/configuration) your `PrismaModule` by using either `forRoot(...)` or `forRootAsync(...)`. 44 | 45 | Use the `PrismaService` via dependency injection in your controllers, resolvers, services, guards and more: 46 | 47 | ```ts 48 | import { Injectable } from '@nestjs/common'; 49 | import { PrismaService } from 'nestjs-prisma'; 50 | 51 | @Injectable() 52 | export class AppService { 53 | constructor(private prisma: PrismaService) {} 54 | 55 | users() { 56 | return this.prisma.user.findMany(); 57 | } 58 | 59 | user(userId: string) { 60 | return this.prisma.user.findUnique({ 61 | where: { id: userId }, 62 | }); 63 | } 64 | } 65 | ``` 66 | 67 | You have access to all exposed methods and arguments of the generated `PrismaClient` through `PrismaService`. 68 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Welcome to [Astro](https://astro.build) 2 | 3 | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics) 4 | 5 | > 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! 6 | 7 | ![basics](https://user-images.githubusercontent.com/4677417/186188965-73453154-fdec-4d6b-9c34-cb35c248ae5b.png) 8 | 9 | ## 🚀 Project Structure 10 | 11 | Inside of your Astro project, you'll see the following folders and files: 12 | 13 | ``` 14 | / 15 | ├── public/ 16 | │ └── favicon.svg 17 | ├── src/ 18 | │ ├── components/ 19 | │ │ └── Card.astro 20 | │ ├── layouts/ 21 | │ │ └── Layout.astro 22 | │ └── pages/ 23 | │ └── index.astro 24 | └── package.json 25 | ``` 26 | 27 | Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name. 28 | 29 | There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components. 30 | 31 | Any static assets, like images, can be placed in the `public/` directory. 32 | 33 | ## 🧞 Commands 34 | 35 | All commands are run from the root of the project, from a terminal: 36 | 37 | | Command | Action | 38 | | :--------------------- | :------------------------------------------------- | 39 | | `npm install` | Installs dependencies | 40 | | `npm run dev` | Starts local dev server at `localhost:3000` | 41 | | `npm run build` | Build your production site to `./dist/` | 42 | | `npm run preview` | Preview your build locally, before deploying | 43 | | `npm run astro ...` | Run CLI commands like `astro add`, `astro preview` | 44 | | `npm run astro --help` | Get help using the Astro CLI | 45 | 46 | ## 👀 Want to learn more? 47 | 48 | Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat). 49 | -------------------------------------------------------------------------------- /docs/src/layouts/CustomDoc.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import Layout from './Base.astro'; 3 | import Navigation from '../components/Navigation.astro'; 4 | import { GITHUB_EDIT_URL, navigation } from '../config'; 5 | import PrevNextNavigation from '../components/PrevNextNavigation.astro'; 6 | 7 | type Props = { 8 | title: string; 9 | githubEditUrl?: string; 10 | }; 11 | 12 | const { title, githubEditUrl } = Astro.props as Props; 13 | 14 | const currentPage = Astro.url.pathname; 15 | const currentPageMatch = currentPage.endsWith('/') 16 | ? currentPage.slice(0, -1) 17 | : currentPage.slice(0); 18 | const currentSection = navigation.find((section) => 19 | section.links.find((link) => link.link == currentPageMatch), 20 | ); 21 | --- 22 | 23 | 24 |
25 | 30 |
31 |
32 |
33 | { 34 | currentSection && ( 35 | 36 | {currentSection.title} 37 | 38 | ) 39 | } 40 |

{title}

41 |
42 | 43 | 44 |
45 | 46 | { 47 | githubEditUrl && ( 48 | 56 | ) 57 | } 58 |
59 |
60 |
61 | -------------------------------------------------------------------------------- /docs/src/layouts/Base.astro: -------------------------------------------------------------------------------- 1 | --- 2 | import 'inter-ui/inter.css'; 3 | import { SEO } from 'astro-seo'; 4 | import HeadCommon from '../components/HeadCommon.astro'; 5 | import Header from '../components/Header.astro'; 6 | import Footer from '../components/Footer.astro'; 7 | 8 | import { OPEN_GRAPH, SITE } from '../config'; 9 | 10 | export interface Props { 11 | title?: string; 12 | } 13 | 14 | const { title } = Astro.props; 15 | 16 | const formattedContentTitle = title ? `${title} - ${SITE.title}` : SITE.title; 17 | --- 18 | 19 | 20 | 21 | 22 | 23 | 24 | 48 | 49 | 50 | 51 | 52 | 57 | 58 | 69 | 70 | 71 |
72 |
73 | 74 |
75 |