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

@stratum-hq/db-adapters

v1.0.0

Published

Stratum PostgreSQL adapters for tenant-scoped query isolation

Readme

@stratum-hq/db-adapters

PostgreSQL adapters for Stratum that automatically scope queries to the current tenant using Row-Level Security. Supports raw pg, Prisma, Drizzle, and Sequelize, plus helpers for enabling RLS on your tables.

Installation

npm install @stratum-hq/db-adapters @stratum-hq/core pg

Raw PostgreSQL

import { Pool } from "pg";
import { RawAdapter, createTenantPool } from "@stratum-hq/db-adapters";
import { getTenantContext } from "@stratum-hq/sdk";

const pool = new Pool({ connectionString: process.env.DATABASE_URL });

// Automatic context from AsyncLocalStorage
const tenantPool = createTenantPool(pool, () => getTenantContext().tenant_id);
const orders = await tenantPool.query("SELECT * FROM orders");

// Or manual, per-query
const adapter = new RawAdapter(pool);
await adapter.query("tenant-id", "SELECT * FROM orders");

Every query is wrapped in a transaction that sets app.current_tenant_id via a parameterized set_config() (SQL-injection-safe), runs your query under the RLS policy, commits, and resets the tenant context before releasing the connection.

ORM Adapters

import { withTenant } from "@stratum-hq/db-adapters";        // Prisma
import { withDrizzleTenant } from "@stratum-hq/db-adapters";  // Drizzle
import { SequelizeAdapter, withTenantScope } from "@stratum-hq/db-adapters"; // Sequelize

// Prisma — all queries scoped to the current tenant
const tenantPrisma = withTenant(prisma, () => getTenantContext().tenant_id, pool);
const orders = await tenantPrisma.order.findMany();

RLS & Migration Helpers

import { enableRLS, createPolicy, migrateTable } from "@stratum-hq/db-adapters";

const client = await pool.connect();
try {
  await client.query("BEGIN");
  // One step: add tenant_id, enable FORCE RLS, create the isolation policy
  await migrateTable(client, "orders");
  await client.query("COMMIT");
} finally {
  client.release();
}

Also available: disableRLS, dropPolicy, isRLSEnabled, addTenantColumn, createIsolationPolicy, and low-level session helpers setTenantContext / resetTenantContext / getCurrentTenantId. Schema-per-tenant and database-per-tenant variants (SchemaRawAdapter, DatabasePoolManager, …) are exported too.

Security

  • All DDL validates table names against /^[a-zA-Z_][a-zA-Z0-9_]*$/.
  • Tenant ID is always set via set_config($1, true) — fully parameterized.
  • enableRLS() always applies FORCE ROW LEVEL SECURITY, preventing bypass by table owners.
  • Always reset the tenant context when returning connections to the pool; createTenantPool handles this for you.

Links

  • Documentation: https://docs.stratum-hq.org/packages/db-adapters/
  • GitHub: https://github.com/stratum-hq/Stratum

License

MIT © Christian Crank