nest-crud-repository-pattern
v1.0.0
Published
A powerful NestJS CRUD generator implementing the Repository Pattern with support for multiple ORMs
Maintainers
Readme
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:
- Install required dependencies
- Generate all necessary files
- 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:
ProductControllerwith all CRUD endpointsProductServicewith business logicProductRepositoryfor database operationsProductentity with basic fields- DTOs for create and update operations
ProductModulewith 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:
- Add more fields to the entity
- Modify validation in DTOs
- Add custom methods to the service
- 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:
- Check our GitHub Issues
- Email us at: [email protected]
Contributing 🌟
We love contributions! To contribute:
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License 📄
This project is licensed under the MIT License - see the LICENSE file for details.
Author ✍️
[Your Name]
- GitHub: @daniel3380rm
- Twitter: @daniel3380rm
Acknowledgments 👏
Special thanks to:
- NestJS team
- All contributors
- Our amazing community
Made with ❤️ for the NestJS community
