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

drizzle-resource

v1.0.1

Published

Schema-driven, type-safe query resources for Drizzle ORM — filtering, sorting, pagination, search, and facets behind one typed contract

Downloads

220

Readme

drizzle-resource

Schema-driven query resources for Drizzle ORM. One typed contract for filtering, sorting, search, pagination, hydration, and facets — define it once, query it consistently across every table endpoint.

Instead of reimplementing sort params, WHERE builders, count queries, and filter sidebars for each endpoint, you declare a resource and get a stable, typed API that handles the entire query pipeline.

Packages and exports

This repository is organized as a workspace monorepo:

  • packages/core contains the core query engine
  • packages/zod and packages/valibot are integration packages
  • packages/drizzle-resource is the single published npm package

Consumers install just drizzle-resource and use subpath exports:

import { createQueryEngine } from "drizzle-resource";
import { queryZodIntegration } from "drizzle-resource/zod";
import { queryValibotIntegration } from "drizzle-resource/valibot";

Features

  • 🔒 Type-safe field paths — sort keys, filter fields, search fields, and facet paths are all inferred from your Drizzle schema and declared relations. Typos fail at compile time.
  • 🔍 Filter trees — AND/OR nested conditions with 11 operators (is, isAnyOf, contains, between, before, after, …)
  • 📄 Pagination — 1-based page + size with configurable defaults
  • ↕️ Sorting — multi-column, default sort, per-resource disabled paths
  • 🔎 Free-text search — ILIKE across configurable field paths, with separate allowed and defaults lists
  • 🗂️ Facets — bucket counts for filter sidebars, traveling in the same request as the main query
  • 🛡️ Scope enforcement — tenant constraints and auth filters that merge into every request and cannot be bypassed
  • ⚙️ Staged pipeline — ids → rows → facets, each stage replaceable independently via strategy.*
  • 🚀 Performance tuning — built-in SQL helpers for custom strategy.ids when you need a hand-tuned query

Install

npm install drizzle-resource    # npm
pnpm add drizzle-resource       # pnpm
bun add drizzle-resource        # bun

Requires drizzle-orm >= 1.0.0-beta as a peer dependency.

Quick start

import { createQueryEngine } from "drizzle-resource";
import { db, relations, schema } from "./db";

const engine = createQueryEngine({ db, schema, relations }).withContext<{ orgId: string }>();

export const ordersResource = engine.defineResource("orders", {
  relations: {
    customer: true,
    orderLines: { with: { product: true } },
  },
  query: {
    scope: (f, ctx) => f.is("customer.orgId", ctx.orgId),
    search: {
      allowed: ["reference", "customer.name", "orderLines.product.name"],
      defaults: ["reference", "customer.name"],
    },
    sort: {
      defaults: [{ key: "createdAt", dir: "desc" }],
      disabled: ["orderLines.product.name"],
    },
    facets: {
      allowed: ["status", "customer.name"],
    },
    defaults: {
      pagination: { pageSize: 25 },
    },
  },
});

const result = await ordersResource.query({
  context: { orgId: "acme" },
  request: {
    pagination: { pageIndex: 1, pageSize: 25 },
    sorting: [{ key: "createdAt", dir: "desc" }],
    search: { value: "laptop", fields: [] },
    filters: [
      { type: "condition", key: "status", operator: "isAnyOf", value: ["pending", "processing"] },
    ],
    facets: [{ key: "status", mode: "exclude-self", limit: 10 }],
  },
});

Documentation

Full docs, benchmark results, and performance guide at drizzle-resource.vercel.app.

License

MIT