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

@origins-digital/query-filter-prisma

v3.1.3

Published

Common query-filter-prisma utilities for all projects

Downloads

486

Readme

@origins-digital/query-filter-prisma

A package for building type-safe Prisma query filters in TypeScript.

Zod compatibility: Works with query filter schemas built using Zod v4.x.

Installation

npm install @origins-digital/query-filter-prisma

Features

  • Type-safe Prisma query filtering
  • Support for complex filter conditions
  • Built-in comparison operators
  • Seamless integration with Prisma's query API
  • Flexible filter grouping (AND/OR/NOT)
  • Support for nested object filtering

Usage

Basic Filtering

import { QueryFilter } from '@origins-digital/query-filter-core';
import { PrismaWhereBuilder } from '@origins-digital/query-filter-prisma';

type User = {
  id: string;
  name: string;
  age: number;
  isActive: boolean;
};

// Simple equality filter
const filter: QueryFilter<User> = {
  name: { eq: 'John' },
  age: { gt: 18 },
  isActive: { is: true },
};

// Convert to Prisma where clause
const prismaWhere = PrismaWhereBuilder.build(filter);

// Use with Prisma client
const users = await prisma.user.findMany({
  where: prismaWhere,
});

Complex Filtering

// Complex filter with AND/OR/NOT
const filter: QueryFilter<User> = {
  or: [
    { name: { contains: 'John' } },
    {
      and: [
        { age: { gt: 18 } },
        { isActive: { is: true } },
        { NOT: { name: { contains: 'Doe' } } },
      ],
    },
  ],
};

const prismaWhere = PrismaWhereBuilder.build(filter);

String Comparisons

const filter: QueryFilter<User> = {
  name: {
    contains: 'John',
    startsWith: 'J',
    endsWith: 'n',
    mode: 'insensitive', // Case-insensitive comparison
  },
};

Numeric Comparisons

const filter: QueryFilter<User> = {
  age: {
    gt: 18, // Greater than
    lt: 65, // Less than
    gte: 21, // Greater than or equal
    lte: 60, // Less than or equal
    in: [18, 21, 30], // In array
  },
};

Boolean Comparisons

const filter: QueryFilter<User> = {
  isActive: {
    is: true, // IS TRUE
    isNot: false, // IS NOT FALSE
  },
};

Date Comparisons

const filter: QueryFilter<User> = {
  createdAt: {
    gt: new Date('2024-01-01'),
    lt: new Date('2024-12-31'),
    between: {
      lower: new Date('2024-01-01'),
      upper: new Date('2024-12-31'),
    },
  },
};

API Reference

PrismaWhereBuilder

class PrismaWhereBuilder {
  static build<Entity>(filter: QueryFilter<Entity>): PrismaQueryFilter<Entity>;
}

PrismaQueryFilter

type PrismaQueryFilter<T> = {
  AND?: PrismaQueryFilter<T> | PrismaQueryFilter<T>[];
  OR?: PrismaQueryFilter<T>[];
  NOT?: PrismaQueryFilter<T> | PrismaQueryFilter<T>[];
  [K in keyof T]?: PrismaFilterFieldComparison<T[K]>;
};

PrismaFilterFieldComparison

type PrismaFilterFieldComparison<FieldType> = {
  // Common operators
  equals?: FieldType;
  in?: FieldType[];
  notIn?: FieldType[];
  lt?: FieldType;
  lte?: FieldType;
  gt?: FieldType;
  gte?: FieldType;
  not?: PrismaFilterFieldComparison<FieldType> | FieldType;

  // String specific operators
  contains?: string;
  startsWith?: string;
  endsWith?: string;
  mode?: 'default' | 'insensitive';
};

Filter Operators

Common Operators

  • equals: Equal to
  • in: In array
  • notIn: Not in array
  • lt: Less than
  • lte: Less than or equal to
  • gt: Greater than
  • gte: Greater than or equal to
  • not: Not equal to or nested comparison

String Operators

  • contains: Contains substring
  • startsWith: Starts with
  • endsWith: Ends with
  • mode: Case sensitivity ('default' or 'insensitive')

Boolean Operators

  • equals: Equal to
  • not: Not equal to

Date Operators

  • equals: Equal to
  • in: In array
  • notIn: Not in array
  • lt: Less than
  • lte: Less than or equal to
  • gt: Greater than
  • gte: Greater than or equal to
  • not: Not equal to or nested comparison

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.