📌 Introduction
Prisma is one of the best ORMs for Node.js and TypeScript. But when building APIs, we often need to:
✅ Filter records dynamically
✅ Sort results based on query parameters
✅ Implement pagination for large datasets
✅ Select only specific fields
While Prisma provides built-in features, implementing these manually can become repetitive. That’s why I created Prisma Query Enhancer—a simple package to handle this efficiently.
🚀 What is Prisma Query Enhancer?
Prisma Query Enhancer is an NPM package that makes Prisma queries cleaner and more reusable.
🔧 Installation
sh
npm install prisma-query-enhancer
🛠️ How to Use It
Let's say we need to fetch users with filtering, sorting, pagination, and selected fields. Here’s how Prisma Query Enhancer simplifies it:
ts
import PrismaQueryEnhancer from 'prisma-query-enhancer';
const query = new PrismaQueryEnhancer(prisma.user, req.query)
.filter()
.sort()
.limitFields()
.paginate()
.execute();
const users = await query;
🔥 No more boilerplate!
📌 How It Works
- filter() → Removes unwanted query fields & applies filtering
- sort() → Sorts based on request parameters
- limitFields() → Selects only the necessary fields
- paginate() → Implements pagination
📦 Why Use Prisma Query Enhancer?
✔ Saves time by reducing boilerplate code
✔ Works seamlessly with Prisma ORM
✔ Handles complex queries effortlessly
🚀 Try It Now!
📦 Install via NPM:
`sh
npm install prisma-query-enhancer`
🔗 GitHub: https://github.com/unwrapsolutions/prisma-query-enhancer
🔗 NPM: https://www.npmjs.com/package/prisma-query-enhancer
💬 Would love your feedback! Let me know what you think. 🚀