A lightweight, TypeScript-compatible package to enhance Prisma queries with filtering, sorting, field selection, and pagination.
First, install the package using npm or yarn:
npm install prisma-query-enhancer
# or
yarn add prisma-query-enhancer
Ensure you have Prisma installed in your project:
npm install @prisma/client
import PrismaQueryEnhancer from "prisma-query-enhancer";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
async function getBookings(req: any) {
const features = new PrismaQueryEnhancer(prisma.booking.findMany, req.query)
.filter()
.sort()
.limitFields()
.paginate();
const bookings = await features.execute();
console.log(bookings);
}
const PrismaQueryEnhancer = require("prisma-query-enhancer");
const { PrismaClient } = require("@prisma/client");
const prisma = new PrismaClient();
async function getBookings(req) {
const features = new PrismaQueryEnhancer(prisma.booking.findMany, req.query)
.filter()
.sort()
.limitFields()
.paginate();
const bookings = await features.execute();
console.log(bookings);
}
- Filtering: Exclude unwanted fields from the query
- Sorting: Sort results based on multiple fields
- Field Selection: Select only the required fields
- Pagination: Easily paginate results
Contributions are welcome! Please follow these steps:
- Fork the repository on GitHub.
-
Clone your forked repository:
git clone https://github.com/unwrapsolutions/prisma-query-enhancer.git
-
Create a new branch:
git checkout -b feature-name
-
Make your changes and commit them:
git commit -m "Add new feature"
-
Push to your branch:
git push origin feature-name
- Submit a pull request 🚀.
This project is licensed under the MIT License. See LICENSE for details.