Compare

Stratum + Knex

SQL query builder for Node.js

Knex is a SQL query builder — not a full ORM — giving you direct control over your queries while handling connection pooling, migrations, and schema building. Stratum pairs naturally with Knex because both operate close to PostgreSQL. Knex builds your queries. Stratum manages tenant hierarchy, config, isolation, and compliance.

Feature comparison

Capability Knex Stratum
Schema management Knex migrations (imperative) Stratum manages tenant tables only
RLS isolation Manual via knex.raw() Automatic policy generation
Schema-per-tenant knex.withSchema() per query Automatic search_path switching
Raw SQL access knex.raw() — first-class Uses pg Pool directly
Config inheritance Not available Built-in, root-to-leaf resolution
Transaction support knex.transaction() Tenant-scoped transactions
GDPR export/purge Build it yourself Built-in per-tenant operations
Connection pooling Tarn.js (built-in) pg Pool

Getting started

knex-with-stratum.ts
import Knex from "knex";
import { Pool } from "pg";
import { Stratum } from "@stratum-hq/lib";

// Knex for query building
const knex = Knex({
  client: "pg",
  connection: process.env.DATABASE_URL,
});

// Stratum for tenancy
const pool = new Pool();
const stratum = new Stratum({ pool });
await stratum.initialize();

// Use Knex for app queries
const rows = await knex("users")
  .withSchema("tenant_acme")
  .select("*");

Things to know

Start building with Knex + Stratum

npm install @stratum-hq/lib pg