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

generic-crud-client

v1.1.10

Published

this is a generic crud client for a nestjs project ...

Downloads

20

Readme

Generic-CRUD-Service Package

This package provides a generic CRUD (Create, Read, Update, Delete) service for the NestJS framework with MongoDB as the database system using Mongoose as the Object Document Mapper (ODM). It is designed to simplify and generalize the process of CRUD operations for any given model.

Usage

The package is meant to be extended by your specific service classes. The specific service class should pass the relevant Mongoose model to the super() call in its constructor.

import { Injectable } from "@nestjs/common";
import { UserModel } from "../models/user.model";
import { GenericCrudService } from "generic-crud-service";

@Injectable()
export class UserService extends GenericCrudService<UserModel> {
  constructor() {
    super(UserModel);
  }
}

Methods

Each method in the service corresponds to a CRUD operation:

create(): Creates a new document in the database. findOne(): Finds a single document in the database. find(): Finds multiple documents in the database. findOneAndUpdate(): Updates a single document in the database and then retrieves it. updateMany(): Updates multiple documents in the database. deleteOne(): Deletes a single document from the database. delete(): Deletes multiple documents from the database.

Each method takes an argument object with a specific shape depending on the operation, and returns a Promise that resolves to the result of the operation.

Feature: prepareQuery

The prepareQuery function is an important feature of this package. This function is used to prepare the condition objects used in query methods (find, findOne, etc.). This function can be provided to the GenericCrudService when creating a new instance.

The prepareQuery function takes two arguments: conditions and data. It's used to transform the query conditions before they are sent to MongoDB. This can be used to enable specific query features that are not supported out of the box by Mongoose or MongoDB.

For instance, you may want to implement case-insensitive queries. A possible prepareQuery function could be:

Copy code
function prepareQuery(conditions, data) {
const updatedConditions = {};

for (let key in conditions) {
updatedConditions[key] = new RegExp(conditions[key], 'i');
}

return updatedConditions;
}

This would turn all query conditions into case-insensitive regular expressions.

Contribution

This package is open-source and welcomes contributions. Please submit a pull request for any enhancements or bug fixes.

License

This package is licensed under the MIT license.