GithubHelp home page GithubHelp logo

terryjoo / nestjs-crud-prisma Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clayrisser/nestjs-crud-prisma

0.0 0.0 0.0 155 KB

crud for restful apis built with nestjs and prisma

License: MIT License

Makefile 31.01% TypeScript 65.36% Dockerfile 1.37% Shell 2.26%

nestjs-crud-prisma's Introduction

nestjs-crud-prisma

GitHub stars

crud for restful apis built with nestjs and prisma

Please ★ this repo if you found it useful ★ ★ ★

Though not required, nestjs-crud-prisma works best with typegraphql-prisma

Installation

npm install --save nestjs-crud-prisma

Dependencies

Usage

  1. Setup prisma to support generating typegraphql.

    This step is not required but recommended. Typegraphql will generate the models from the schema.prisma.

    schema.prisma

    generator typegraphql {
      provider = "../node_modules/typegraphql-prisma/generator.js"
      output   = "../src/generated/type-graphql"
    }
    
  2. Create a service that injects the prisma service.

    Although it's not required, I recommend nestjs-prisma to get the prisma service. Also, notice I'm getting the model from the generated typegraphql.

    user.service.ts

    import { Injectable } from '@nestjs/common';
    import { PrismaCrudService } from 'nestjs-crud-prisma';
    import { PrismaService } from 'nestjs-prisma';
    import { User } from '../../generated/type-graphql';
    
    @Injectable()
    export class UserService extends PrismaCrudService<User> {
      constructor(prisma: PrismaService) {
        super(prisma, User); // make sure you pass in the model
      }
    }
  3. Create a crud controller that injects the previous service.

    user.controller.ts

    import { Controller } from '@nestjs/common';
    import { Crud } from '@nestjsx/crud';
    import { UserService } from './user.service';
    import { User } from '../../generated/type-graphql';
    
    @Crud({
      model: {
        type: User
      },
      params: {
        id: {
          field: 'id',
          type: 'string',
          primary: true
        }
      },
      query: {
        alwaysPaginate: true
      }
    })
    @Controller('users')
    export class UserController {
      constructor(public service: UserService) {}
    }

Support

Submit an issue

Screenshots

Contribute a screenshot

Contributing

Review the guidelines for contributing

License

MIT License

Jam Risser © 2020

Changelog

Review the changelog

Credits

Support on Liberapay

A ridiculous amount of coffee ☕ ☕ ☕ was consumed in the process of building this project.

Add some fuel if you'd like to keep me going!

Liberapay receiving Liberapay patrons

nestjs-crud-prisma's People

Contributors

austinwebdeveloper avatar clayrisser 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.