GithubHelp home page GithubHelp logo

guanxueying1230 / nestjs-prisma Goto Github PK

View Code? Open in Web Editor NEW

This project forked from notiz-dev/nestjs-prisma

0.0 0.0 0.0 1.42 MB

Easy Prisma support for your NestJS application

Home Page: https://nestjs-prisma.dev

License: MIT License

JavaScript 2.47% TypeScript 95.64% Dockerfile 1.89%

nestjs-prisma's Introduction

nestjs-prisma

Easy Prisma support for your NestJS application.

Build Status Total Downloads npm package License

Installation

Automatic Install

Use the nest add command to automatically setup the library, Prisma and Docker (optionally):

nest add nestjs-prisma

Manual Install

Add nestjs-prisma library to your NestJS application:

# npm
npm install nestjs-prisma

# yarn
yarn add nestjs-prisma

Furthermore, setup Prisma in your NestJS application, if you haven't already.

npm i -D prisma
npm install @prisma/client

npx prisma init

Basic usage

Add PrismaModule to the imports section in your AppModule or other modules to gain access to PrismaService.

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:

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.

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.

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

npm i -g @angular-devkit/schematics-cli

Now build the schematics and run the schematic.

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 which also applies to Nest.

nestjs-prisma's People

Contributors

marcjulian avatar omar-dulaimi avatar gonza7aav avatar yusupova avatar ali-master avatar le-ar avatar donnguyen avatar megane42 avatar loskir avatar liaosankai avatar suryatmodulus avatar yicrotkd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.