nest-crud-repository-pattern v1.0.0
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 šāāļø
- Open your terminal
- 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:
- Run the generator:
bash nest-crud-gen g
- Enter details:
bash ? Enter the resource name: product ? Which ORM would you like to use? TypeORM
- The generator will create:
ProductController
with all CRUD endpointsProductService
with business logicProductRepository
for database operationsProduct
entity with basic fields- DTOs for create and update operations
ProductModule
with proper configurations
- 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
- Dependencies Installation Failed
bash npm install --legacy-peer-deps missing-dependencies
- Type Errors Make sure to install all type definitions:
bash npm install @types/node -D
- 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 āļø
- GitHub: @daniel3380rm
- Twitter: @daniel3380rm
Acknowledgments š
Special thanks to:
- NestJS team
- All contributors
- Our amazing community
Made with ā¤ļø for the NestJS community
5 months ago