prisma-query-enhancer
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Prisma Query Enhancer 🚀

A lightweight, TypeScript-compatible package to enhance Prisma queries with filtering, sorting, field selection, and pagination.

📦 Installation

First, install the package using npm or yarn:

npm install prisma-query-enhancer
# or
yarn add prisma-query-enhancer

🔧 Prerequisites

Ensure you have Prisma installed in your project:

npm install @prisma/client

🔧 Usage

TypeScript Example

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);
}

JavaScript Example

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);
}

📜 Features

  • 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

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository on GitHub.
  2. Clone your forked repository:
    git clone https://github.com/unwrapsolutions/prisma-query-enhancer.git
  3. Create a new branch:
    git checkout -b feature-name
  4. Make your changes and commit them:
    git commit -m "Add new feature"
  5. Push to your branch:
    git push origin feature-name
  6. Submit a pull request 🚀.

🌟 License

This project is licensed under the MIT License. See LICENSE for details.

Package Sidebar

Install

npm i prisma-query-enhancer

Weekly Downloads

6

Version

1.0.5

License

MIT

Unpacked Size

9.52 kB

Total Files

8

Last publish

Collaborators

  • unwrapsolutions