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
});
});
});
Errors
Common errors & fixes
Error: PGL is not a constructor
Attempting to import/use PGL in a CommonJS environment without proper ESM handling.
fixEnsure 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.
fixUse `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.
fixWrap your test code inside `withRLS(pool, { role: '...' }, async () => { ... })`. Audit
Dependencies
drizzle-ormrequiredpeer dependency; core ORM to interact with PostgreSQL
pgrequiredpeer dependency; PostgreSQL client for Node.js