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

@tenantscale/drizzle

v0.1.1

Published

Drizzle ORM tenant query guard for TenantScale

Downloads

208

Readme

@tenantscale/drizzle

Tenant-safe Drizzle ORM helpers for TenantScale.

Install

npm install @tenantscale/drizzle
# or
pnpm add @tenantscale/drizzle

Usage

This package provides a tenantFilter helper that creates a Drizzle SQL expression for filtering queries by tenant ID. It works with Drizzle's expression-based query builder and can be combined with other conditions using and(), or(), etc.

import { tenantFilter } from '@tenantscale/drizzle'
import { and, eq } from 'drizzle-orm'

// Select with tenant filter
const tickets = await db
  .select()
  .from(tickets)
  .where(tenantFilter(tickets.tenant_id, tenantId))

// Combine with other conditions
const openTickets = await db
  .select()
  .from(tickets)
  .where(and(
    eq(tickets.status, 'open'),
    tenantFilter(tickets.tenant_id, tenantId)
  ))

// Update with tenant filter
await db
  .update(tickets)
  .set({ status: 'closed' })
  .where(and(
    eq(tickets.id, ticketId),
    tenantFilter(tickets.tenant_id, tenantId)
  ))

// Delete with tenant filter
await db
  .delete(tickets)
  .where(tenantFilter(tickets.tenant_id, tenantId))

Design

This package takes a deliberately scoped approach:

  • Proxy-based approach rejected: The initial design used a Proxy to automatically inject tenant filters, but this doesn't work with Drizzle's expression-based API where .where() expects SQL expressions like eq(col, val), not column/value tuples.
  • Explicit filtering: The tenantFilter helper returns a proper Drizzle SQL expression that you explicitly include in your queries. This ensures compatibility with Drizzle's actual API.
  • No magic: Users must explicitly add the tenant filter to their queries, which makes the behavior clear and predictable.

Limitations

  • This helper only provides the tenant filter expression. It does not automatically inject tenant filters into queries.
  • Users must remember to include tenantFilter in every query that should be tenant-scoped.
  • For insert operations, you must manually add the tenant ID to the values object (this is not handled by the helper).

Error Handling

The helper throws an error if tenantId is empty or undefined:

tenantFilter(tickets.tenant_id, '') // Throws: tenantId is required