Registry / testing / drizzle-orm-test

drizzle-orm-test

JSON →
library2.16.0jsnpmunverified

drizzle-orm-test (v2.16.0) is a drop-in replacement for pgsql-test that enables Drizzle ORM to work seamlessly with PostgreSQL context management and Row-Level Security (RLS) testing. It wraps database connections to manage RLS policies and test user roles in integration tests, supporting Postgres and TimescaleDB. Updated quarterly, it provides a test helper that sets up RLS contexts automatically, reducing boilerplate compared to manually managing pg pools or using pgsql-test directly.

npm install drizzle-orm-test
INSTALL
IMPORT
SIG · DRIZZLE-ORM-TEST
D
drizzle-orm-test
testingjavascriptv2.16.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PGL
✓ import { PGL } from 'drizzle-orm-test'
✗ const PGL = require('drizzle-orm-test/PGL')
ESM only; named import from the main package. PGL is a drop-in for pg's native Pool with RLS support.
createDrizzle
✓ import { createDrizzle } from 'drizzle-orm-test'
✗ import createDrizzle from 'drizzle-orm-test'
Named export, not default. Creates a Drizzle ORM instance with test context.
withRLS
✓ import { withRLS } from 'drizzle-orm-test'
Helper function to wrap test cases with RLS context. Available since v2.0.

Shows how to set up RLS testing with Drizzle ORM, testcontainers, and PGL pool.

import { PGL, createDrizzle, withRLS } from 'drizzle-orm-test'; import { pgTable, text, integer } from 'drizzle-orm/pg-core'; import { eq } from 'drizzle-orm'; import { PostgreSqlContainer } from '@testcontainers/postgresql'; const users = pgTable('users', { id: integer('id').primaryKey(), name: text('name'), role: text('role'), }); describe('RLS', () => { let container; let pool; let db; // Drizzle instance beforeAll(async () => { container = await new PostgreSqlContainer().start(); pool = new PGL({ connectionString: container.getConnectionUri() }); db = createDrizzle(pool); // Enable RLS and create tables await pool.query(`CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, role TEXT)`); await pool.query(`ALTER TABLE users ENABLE ROW LEVEL SECURITY`); await pool.query(`CREATE POLICY user_isolation ON users USING (role = current_setting('rls.role'))`); }); afterAll(async () => { await pool.end(); await container.stop(); }); it('should respect RLS policies', async () => { await withRLS(pool, { role: 'admin' }, async () => { await db.insert(users).values({ id: 1, name: 'Alice', role: 'admin' }); }); await withRLS(pool, { role: 'user' }, async () => { const result = await db.select().from(users); expect(result).toEqual([]); // user role cannot see admin records }); }); });
Debug
Known issues
breakingVersion 2.0.0 dropped support for pgsql-test's native queries; use PGL instead of pg.Pool.
fix
Replace `new pg.Pool(...)` with `new PGL(...)` and ensure all queries go through Drizzle ORM.
affects: >=2.0.0
breakingcreateDrizzle no longer accepts a callback; it returns a Drizzle instance directly.
fix
Use `const db = createDrizzle(pool)` instead of `createDrizzle(pool, (db) => ...)`.
affects: >=1.5.0
deprecatedwithRLS now requires passing the pool as first argument; previous versions did not.
fix
Update calls to `withRLS(pool, context, fn)`.
affects: >=2.0.0
gotchaPGL does not support all pg.Pool options; notably `statement_timeout` and `query_timeout` are ignored.
fix
Set timeouts via Drizzle ORM configuration or use pg.Pool directly (without RLS).
affects: all
Errors
Common errors & fixes
Error: PGL is not a constructor
Attempting to import/use PGL in a CommonJS environment without proper ESM handling.
fix
Ensure your project is configured for ESM ("type": "module" in package.json) or use dynamic import: const { PGL } = await import('drizzle-orm-test');
TypeError: createDrizzle is not a function
Trying to use a default import instead of named import.
fix
Use `import { createDrizzle } from 'drizzle-orm-test'`.
Error: current_setting('rls.role') not found
RLS context was not set before query; withRLS did not execute properly.
fix
Wrap your test code inside `withRLS(pool, { role: '...' }, async () => { ... })`.
Upgrade
Version history
2.16.0latest on npm
Audit
Dependencies
drizzle-ormrequiredpeer dependency; core ORM to interact with PostgreSQL
pgrequiredpeer dependency; PostgreSQL client for Node.js
Agent activity
7 hits · last 30 days
node
6
Resources
drizzle-orm-test — npm install drizzle-orm-test · libregistry