Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/notiz-dev/nestjs-prisma
Easy Prisma support for your NestJS application
https://github.com/notiz-dev/nestjs-prisma
nestjs prisma
Last synced: about 21 hours ago
JSON representation
Easy Prisma support for your NestJS application
- Host: GitHub
- URL: https://github.com/notiz-dev/nestjs-prisma
- Owner: notiz-dev
- License: mit
- Created: 2020-08-05T14:42:39.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-02T12:11:49.000Z (about 1 month ago)
- Last Synced: 2024-12-29T02:35:18.655Z (5 days ago)
- Topics: nestjs, prisma
- Language: TypeScript
- Homepage: https://nestjs-prisma.dev
- Size: 1.6 MB
- Stars: 607
- Watchers: 1
- Forks: 50
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
nestjs-prisma
Easy Prisma support for your NestJS application.## Installation
### Automatic Install
Use the [nest add](https://nestjs-prisma.dev/docs/schematics) command to automatically setup the library, Prisma and Docker (optionally):
```sh
nest add nestjs-prisma
```### Manual Install
Add `nestjs-prisma` library to your [NestJS application](https://docs.nestjs.com/#installation):
```sh
# npm
npm install nestjs-prisma# yarn
yarn add nestjs-prisma
```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.
```sh
npm i -D prisma
npm install @prisma/clientnpx prisma init
```## Basic usage
Add `PrismaModule` to the `imports` section in your `AppModule` or other modules to gain access to `PrismaService`.
```ts
import { Module } from '@nestjs/common';
import { PrismaModule } from 'nestjs-prisma';@Module({
imports: [PrismaModule.forRoot()],
})
export class AppModule {}
```Use the `PrismaService` via dependency injection in your controller, resolver, services, guards and more:
```ts
import { Injectable } from '@nestjs/common';
import { PrismaService } from 'nestjs-prisma';@Injectable()
export class AppService {
constructor(private prisma: PrismaService) {}users() {
return this.prisma.user.findMany();
}user(userId: string) {
return this.prisma.user.findUnique({
where: { id: userId },
});
}
}
```You have access to all exposed methods and arguments of the generated `PrismaClient` through `PrismaService`.
## Documentation
Visit our [official documentation](https://nestjs-prisma.dev/docs/installation).
## Contributing
You are welcome to contribute to this project.
The code is split up into three directories:
```
+-- docs
+-- examples
+-- lib
+-- schematics
```The `docs` directory contains an astro website and the [docs content](./docs/src/content/docs).
The `examples` directory contains example applications.
The `lib` directory contains everything exposed by `nestjs-prisma` as a library.
The `schematics` directory contains the blue prints for installing the library with the schematic command.
Here are some tips if you like to make changes to the schematics.
Install `@angular-devkit/schematics-cli` to be able to use `schematics` command
```bash
npm i -g @angular-devkit/schematics-cli
```Now build the schematics and run the schematic.
```bash
npm run build:schematics
# or
npm run dev:schematics# dry-run
schematics .:nest-add# execute schematics
schematics .:nest-add --debug false
# or
schematics .:nest-add --dry-run false
```Helpful article about [Custom Angular Schematics](https://medium.com/@tomastrajan/total-guide-to-custom-angular-schematics-5c50cf90cdb4) which also applies to Nest.