npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@noflame/nestjs-prisma-crud

v1.0.1

Published

CRUD package for NestJS and Prisma ORM

Downloads

5

Readme

nestjs-prisma-crud

CRUD utility for simple REST use cases. Builds on top of NestJS and Prisma. Inspired by @nestjsx/crud.

Installation

npm i nestjs-prisma-crud --save
npm i nestjs-prisma-crud-schematics --save-dev

Why

When building REST API's there is common functionality that we would prefer not to implement again and again. This package offers minimal and opinionated out of the box solutions for some of those (see features below).

✔ Features

An overview of the provided functionality:

  1. Advanced client side joining, sorting, filtering and pagination via query parameters
    • Any valid prisma .where can be sent by the frontend.
    • Server side validation to safeguard against arbitrarily deep .join or .where clauses by clients.
    • Support for including only specific properties in the response.
  2. Access control
    • @AccessPolicy decorator with default utilities that support functionalities similar to RBAC/ABAC.
    • Custom policy support.
  3. Atomic operations
    • Supports POST/PATCH with nested objects.
    • Transaction support when extending controller functionality.
  4. Schematics
    • crud-resource: a modified NestJS resource schematic that scaffolds the entire CRUD module for you. One-line scaffolding with: nest g -c nestjs-prisma-crud-schematics crud-resource <YOUR-TABLE-NAME-HERE>
  5. Plug and play
    • Can be used alongside your other non nestjs-prisma-crud controllers.
    • You can still use PrismaCrudService and @AccessPolicy in your custom controllers if you want to retain some of nestjs-prisma-crud's functionalities.

Quickstart

Assumes both NestJS and Prisma2 are already setup. See Getting Started.

  1. Install nestjs-prisma-crud and nestjs-prisma-crud-schematics:

    npm i nestjs-prisma-crud
    npm i nestjs-prisma-crud-schematics --save-dev
  2. Generate the entire crud module with a single command (replace post with your model's name):

    nest g -c nestjs-prisma-crud-schematics crud-resource post
  3. Setup your service and controller

    // post.service.ts
    import { Injectable } from '@nestjs/common';
    import { PrismaCrudService } from 'nestjs-prisma-crud';
    
    @Injectable()
    export class PostService extends PrismaCrudService {
        constructor() {
            super({
                model: 'post',
                allowedJoins: ['comments.author'],
            });
        }
    }
    
    // post.controller.ts
    import { PostService } from './post.service';
    
    @Controller('post')
    export class PostController {
        constructor(private readonly postService: PostService) {}
    
        @Get()
        async findMany(@Query('crudQuery') crudQuery: string) {
            const matches = await this.postService.findMany(crudQuery);
            return matches;
        }
    }

Documentation

Go here for full documentation.

License

MIT licensed

Built with

TSDX np yarn 1.22.10