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

tenancyjs-adapter-drizzle

v0.2.1

Published

Fail-closed Drizzle tenant isolation for PostgreSQL and MySQL.

Readme

tenancyjs-adapter-drizzle

Fail-closed Drizzle 0.45 tenant isolation for PostgreSQL and MySQL on Node.js 24+.

New to TenancyJS? Start with the docs → — install, the tenancyjs-cli CLI, and how this package fits with an adapter + integration.

The adapter returns callback-scoped plain-value table facades. It never exposes the native Drizzle database/transaction, SQL expressions, relational query API, joins, migrations, or raw execution.

PostgreSQL row-level

import { drizzle } from "drizzle-orm/node-postgres";
import {
  createDrizzleTenancy,
  createPostgresDrizzleBinding,
} from "tenancyjs-adapter-drizzle";

const tenancy = createDrizzleTenancy({
  manager,
  database: createPostgresDrizzleBinding(drizzle({ client: pool })),
  tenantTables: [{ table: posts, policyName: "posts_tenant_isolation" }],
});

await tenancy.validate(); // validates runtime role + ENABLE/FORCE RLS + policy
const rows = await tenancy.run((client) => client.table(posts).findMany());

Use a non-owner, non-superuser, non-BYPASSRLS runtime role. The deployed policy must use the tenancyjs.tenant_id and tenancyjs.is_central transaction-local settings in both USING and WITH CHECK. The migration role and base Drizzle database stay private.

PostgreSQL schema-per-tenant

Use an unqualified pgTable; the adapter owns transaction-local search_path:

createDrizzleTenancy({
  manager,
  database: createPostgresDrizzleBinding(db),
  strategy: "schemaPerTenant",
  schema: (tenant) => tenant.schemaName,
  tenantTables: [{ table: posts }],
});

The default shared-role mode is adapter-enforced. Add a per-tenant role resolver for database-enforced sibling-schema denial.

Database-per-tenant

createDrizzleTenancy({
  manager,
  database: landlordBinding,
  strategy: "databasePerTenant",
  tenantTables: [{ table: posts }],
  connection: (tenant) => ({
    key: tenant.databaseKey, // opaque; never a URL
    create: () => {
      const pool = createTenantPool(tenant.secretRef);
      return createPostgresDrizzleBinding(drizzle({ client: pool }), {
        close: () => pool.end(),
      });
    },
  }),
});

The same pattern works with createMySqlDrizzleBinding. Always provide close for cache-owned tenant pools.

MySQL guarantee

MySQL row-level is adapter-enforced and experimental: every predicate is scoped by the protected facade, but MySQL has no RLS backstop. Retaining/using the native Drizzle database bypasses the guarantee. MySQL schema-per-tenant does not exist as a separate mode; use database-per-tenant.

Supported protected operations

findMany, findOne, count, create, createMany, update, and delete accept plain scalar equality only. Tenant ownership is injected/validated, and updates cannot move rows. Unknown tables, raw SQL, nested/relational operations, query objects, and arbitrary operators are rejected or absent.

Call validate() before serving traffic and close() during shutdown.