1.0.0 • Published 5 months ago

nest-crud-repository-pattern v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

NestJS CRUD Generator šŸš€

A powerful and user-friendly CLI tool that generates complete CRUD operations for NestJS applications with support for multiple ORMs.

Features ✨

  • šŸ› ļø Generates complete CRUD operations
  • šŸ”Œ Supports multiple ORMs:
    • TypeORM
    • Prisma
    • Mongoose
    • Sequelize
    • MikroORM
  • šŸ“ Creates all necessary files:
    • Controller
    • Service
    • Repository
    • Entity
    • DTOs
    • Module
  • šŸ¤– Automatic dependency installation
  • šŸŽØ Clean and consistent code structure

Installation šŸ“¦

bash

npm install -g nestjs-crud-generator

Quick Start šŸƒā€ā™‚ļø

  1. Open your terminal
  2. Navigate to your NestJS project:

bash cd your-nestjs-project 3. Run the generator:

bash nest-crud-gen generate or use the shorthand:

bash nest-crud-gen g

Step-by-Step Guide šŸ“

1. Enter Resource Name

When prompted, enter the name of your resource (e.g., "user", "product", "order").

Example:

bash ? Enter the resource name: user

2. Select ORM

Choose your preferred ORM from the list:

  • TypeORM
  • Prisma
  • Mongoose
  • Sequelize
  • MikroORM

Example:

bash ? Which ORM would you like to use? āÆ TypeORM - Most popular ORM for TypeScript/Node.js Prisma - Modern DB toolkit with type safety Mongoose - Elegant MongoDB ODM Sequelize - Feature-rich ORM for SQL databases MikroORM - TypeScript ORM with Identity Map pattern

3. Wait for Generation

The tool will: 1. Install required dependencies 2. Generate all necessary files 3. Set up proper configurations

Generated Files Structure šŸ“

src/ └── your-resource/ ā”œā”€ā”€ dto/ │ ā”œā”€ā”€ create-your-resource.dto.ts │ └── update-your-resource.dto.ts ā”œā”€ā”€ entities/ │ └── your-resource.entity.ts ā”œā”€ā”€ your-resource.controller.ts ā”œā”€ā”€ your-resource.service.ts ā”œā”€ā”€ your-resource.repository.ts └── your-resource.module.ts

Example Usage šŸ’”

Let's create a complete CRUD for a "product" resource:

  1. Run the generator:

bash nest-crud-gen g

  1. Enter details:

bash ? Enter the resource name: product ? Which ORM would you like to use? TypeORM

  1. The generator will create:
  • ProductController with all CRUD endpoints
  • ProductService with business logic
  • ProductRepository for database operations
  • Product entity with basic fields
  • DTOs for create and update operations
  • ProductModule with proper configurations
  1. Your endpoints will be available at:
  • GET /product - Get all products
  • GET /product/:id - Get one product
  • POST /product - Create product
  • PATCH /product/:id - Update product
  • DELETE /product/:id - Delete product

Customization šŸŽØ

After generation, you can: 1. Add more fields to the entity 2. Modify validation in DTOs 3. Add custom methods to the service 4. Extend controller functionality

Troubleshooting šŸ”§

Common Issues

  1. Dependencies Installation Failed

bash npm install --legacy-peer-deps missing-dependencies

  1. Type Errors Make sure to install all type definitions:

bash npm install @types/node -D

  1. Path Issues Ensure you're running the command in your NestJS project root.

Support šŸ¤

If you encounter any issues or need help: 1. Check our GitHub Issues 3. Email us at: daniel.3380.rm@gmail.com

Contributing 🌟

We love contributions! To contribute: 1. Fork the repository 2. Create your feature branch 3. Commit your changes 4. Push to the branch 5. Create a Pull Request

License šŸ“„

This project is licensed under the MIT License - see the LICENSE file for details.

Author āœļø

Your Name

Acknowledgments šŸ‘

Special thanks to:

  • NestJS team
  • All contributors
  • Our amazing community

Made with ā¤ļø for the NestJS community