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

easy-filters

v2.0.0

Published

Dynamic filter generation and query building for Drizzle ORM with Zod validation

Readme

Easy Filters

A powerful utility library for generating dynamic filters and query builders for Drizzle ORM with automatic Zod schema validation.

Features

  • 🔍 Dynamic filter generation based on column types
  • ✅ Automatic Zod schema generation
  • 🎯 Type-safe query building
  • 📦 Support for multiple filter operations per column
  • 🚀 Works with string, number, date, and boolean columns

Installation

npm install easy-filters

Peer Dependencies

This package requires:

  • drizzle-orm >= 0.29.0
  • zod >= 3.22.0

Usage

Basic Example

import { generateFilterSchema, applyFilters } from 'easy-filters'
import { users } from './schema'

// Define which filters you want for each column
const filtersMap = {
  name: ['contains', 'eq', 'starts_with'],
  age: ['eq', 'gt', 'gte', 'lt', 'lte', 'between'],
  email: ['contains', 'eq'],
  createdAt: ['gte', 'lte', 'between'],
  isActive: ['eq']
}

// Generate Zod schema for validation
const FilterSchema = generateFilterSchema(users, filtersMap)

// Parse and validate query parameters
const queryParams = FilterSchema.parse({
  name_contains: 'Text',
  age_gte: 18,
  isActive_equals: true
})

// Apply filters to your Drizzle query
const whereClause = applyFilters(users, queryParams, filtersMap)

const results = await db
  .select()
  .from(users)
  .where(whereClause)

Available Filters by Type

String Columns

  • contains - Case-insensitive substring match
  • eq - Exact match
  • starts_with - Starts with pattern
  • ends_with - Ends with pattern

Number Columns

  • eq - Equal to
  • gt - Greater than
  • gte - Greater than or equal
  • lt - Less than
  • lte - Less than or equal
  • between - Between two values (inclusive)

Date Columns

  • eq - Equal to date
  • gte - Greater than or equal
  • lte - Less than or equal
  • between - Between two dates

Boolean Columns

  • eq - Equal to true/false

API Reference

generateFilterSchema(table, filtersMap)

Generates a Zod schema based on your table and filter configuration.

Parameters:

  • table - Drizzle table definition
  • filtersMap - Object mapping column names to allowed filter operations

Returns: Zod schema object

applyFilters(table, queryParams, filtersMap)

Builds and applies filter conditions to your query.

Parameters:

  • table - Drizzle table definition
  • queryParams - Validated query parameters
  • filtersMap - Object mapping column names to allowed filter operations

Returns: SQL condition that can be passed to .where()

buildFilters(table, queryParams, filtersMap)

Lower-level function that builds an array of SQL conditions.

Parameters:

  • table - Drizzle table definition
  • queryParams - Query parameters
  • filtersMap - Object mapping column names to allowed filter operations

Returns: Array of SQL conditions

Complete Example with Express

import express from 'express'
import { drizzle } from 'drizzle-orm/node-postgres'
import { generateFilterSchema, applyFilters } from 'easy-filters'
import { users } from './schema'

const app = express()
const db = drizzle(process.env.DATABASE_URL!)

const filtersMap = {
  name: ['contains', 'eq'],
  age: ['gte', 'lte', 'between'],
  email: ['contains'],
  createdAt: ['gte', 'lte'],
  isActive: ['eq']
}

const FilterSchema = generateFilterSchema(users, filtersMap)

app.get('/users', async (req, res) => {
  try {
    // Validate query parameters
    const filters = FilterSchema.parse(req.query)
    
    // Apply filters
    const whereClause = applyFilters(users, filters, filtersMap)
    
    // Execute query
    const results = await db
      .select()
      .from(users)
      .where(whereClause)
    
    res.json(results)
  } catch (error) {
    res.status(400).json({ error: error.message })
  }
})

Example Query URLs

/users?name_contains=john&age_gte=18
/[email protected]&isActive_equals=true
/users?age_between_min=18&age_between_max=65
/users?createdAt_gte=2024-01-01&createdAt_lte=2024-12-31

TypeScript Support

This package is written in TypeScript and includes type definitions out of the box.

License

MIT

Contributing

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

Support

If you encounter any issues or have questions, please file an issue on the GitHub repository.