npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prisma-query-parser

v1.0.0

Published

A zero-dependency query parser that converts API query parameters into Prisma ORM arguments

Downloads

169

Readme

Prisma Query Parser

A zero-dependency, lightweight utility that automatically parses URL query parameters (like ?page=1&limit=10&sort=-createdAt) into Prisma ORM query arguments (skip, take, where, orderBy, select, include).

Features

  • 🚀 Zero Dependencies: Pure TypeScript, no external bloat.
  • 🔄 Pagination: Automatically handles page and limit.
  • 📊 Sorting: Support for multiple fields and descending/ascending order.
  • 🎯 Field Selection: Pick exactly which fields to return, including nested relations using dot notation (e.g., owner.name).
  • 🔗 Relations: Fetch related models easily via include.
  • 🔍 Advanced Filtering: Support for Prisma's advanced operators (gte, lte, contains, in, notIn).

Installation

npm install prisma-query-parser

or

yarn add prisma-query-parser

Quick Start (Express.js Example)

Just pass your req.query directly into the PrismaQueryBuilder.

import { Request, Response } from 'express';
import { PrismaQueryBuilder } from 'prisma-query-parser';
import { prisma } from './your-prisma-client';

export const getUsers = async (req: Request, res: Response) => {
  // 1. Initialize the builder with req.query
  const builder = new PrismaQueryBuilder(req.query);
  
  // 2. Build the Prisma query options
  const queryOptions = builder.build();

  // 3. Execute the Prisma query
  const users = await prisma.user.findMany(queryOptions);
  const total = await prisma.user.count({ where: queryOptions.where });

  // 4. Send response with optional pagination metadata
  res.json({
    data: users,
    meta: builder.getMeta(total, users.length)
  });
};

How to use Query Parameters

1. Pagination (page & limit)

GET /users?page=2&limit=5

2. Sorting (sort)

Prefix with - for descending order. Separate multiple fields by commas.

GET /users?sort=-createdAt,name

3. Field Selection (fields)

Limit the returned columns. Supports nested fields via dot notation!

GET /users?fields=id,name,email,profile.bio

4. Include Relations (include)

Fetch related tables.

GET /users?include=posts,profile

💡 Pro Tip: If you only need specific fields from a relation, use fields with dot notation (e.g., fields=profile.bio). You DO NOT need to pass include=profile. The builder automatically resolves the join, keeping your response payload clean and minimal!

5. Filtering (Exact Match)

Filter by exact values.

GET /users?role=ADMIN&city=Bandung

6. Advanced Filtering (Prisma Operators)

Use brackets to utilize Prisma's native comparison operators.

# Text search
GET /users?name[contains]=John

# Number comparisons
GET /products?price[gte]=1000&price[lte]=5000

# IN Array
GET /users?role[in]=ADMIN,MODERATOR

Type Conversion Configuration

Because query strings are always text, you might need to convert some fields into numbers or booleans before Prisma reads them.

You can pass a configuration object into the build() method:

const queryOptions = builder.build({
  numberFields: ['price', 'stock', 'rating'],
  booleanFields: ['isActive', 'isPublished']
});

License

MIT License