{"id":40849,"library":"drizzle-orm-test","title":"drizzle-orm-test","description":"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.","status":"active","version":"2.16.0","language":"javascript","source_language":"en","source_url":"https://github.com/constructive-io/constructive","tags":["javascript","postgres","postgresql","drizzle","drizzle-orm","testing","integration-tests","database-testing","pg","typescript"],"install":[{"cmd":"npm install drizzle-orm-test","lang":"bash","label":"npm"},{"cmd":"yarn add drizzle-orm-test","lang":"bash","label":"yarn"},{"cmd":"pnpm add drizzle-orm-test","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; core ORM to interact with PostgreSQL","package":"drizzle-orm","optional":false},{"reason":"peer dependency; PostgreSQL client for Node.js","package":"pg","optional":false}],"imports":[{"note":"ESM only; named import from the main package. PGL is a drop-in for pg's native Pool with RLS support.","wrong":"const PGL = require('drizzle-orm-test/PGL')","symbol":"PGL","correct":"import { PGL } from 'drizzle-orm-test'"},{"note":"Named export, not default. Creates a Drizzle ORM instance with test context.","wrong":"import createDrizzle from 'drizzle-orm-test'","symbol":"createDrizzle","correct":"import { createDrizzle } from 'drizzle-orm-test'"},{"note":"Helper function to wrap test cases with RLS context. Available since v2.0.","wrong":null,"symbol":"withRLS","correct":"import { withRLS } from 'drizzle-orm-test'"}],"quickstart":{"code":"import { PGL, createDrizzle, withRLS } from 'drizzle-orm-test';\nimport { pgTable, text, integer } from 'drizzle-orm/pg-core';\nimport { eq } from 'drizzle-orm';\nimport { PostgreSqlContainer } from '@testcontainers/postgresql';\n\nconst users = pgTable('users', {\n  id: integer('id').primaryKey(),\n  name: text('name'),\n  role: text('role'),\n});\n\ndescribe('RLS', () => {\n  let container;\n  let pool;\n  let db; // Drizzle instance\n\n  beforeAll(async () => {\n    container = await new PostgreSqlContainer().start();\n    pool = new PGL({ connectionString: container.getConnectionUri() });\n    db = createDrizzle(pool);\n    // Enable RLS and create tables\n    await pool.query(`CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, role TEXT)`);\n    await pool.query(`ALTER TABLE users ENABLE ROW LEVEL SECURITY`);\n    await pool.query(`CREATE POLICY user_isolation ON users USING (role = current_setting('rls.role'))`);\n  });\n\n  afterAll(async () => {\n    await pool.end();\n    await container.stop();\n  });\n\n  it('should respect RLS policies', async () => {\n    await withRLS(pool, { role: 'admin' }, async () => {\n      await db.insert(users).values({ id: 1, name: 'Alice', role: 'admin' });\n    });\n    await withRLS(pool, { role: 'user' }, async () => {\n      const result = await db.select().from(users);\n      expect(result).toEqual([]); // user role cannot see admin records\n    });\n  });\n});","lang":"typescript","description":"Shows how to set up RLS testing with Drizzle ORM, testcontainers, and PGL pool."},"warnings":[{"fix":"Replace `new pg.Pool(...)` with `new PGL(...)` and ensure all queries go through Drizzle ORM.","message":"Version 2.0.0 dropped support for pgsql-test's native queries; use PGL instead of pg.Pool.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use `const db = createDrizzle(pool)` instead of `createDrizzle(pool, (db) => ...)`.","message":"createDrizzle no longer accepts a callback; it returns a Drizzle instance directly.","severity":"breaking","affected_versions":">=1.5.0"},{"fix":"Update calls to `withRLS(pool, context, fn)`.","message":"withRLS now requires passing the pool as first argument; previous versions did not.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Set timeouts via Drizzle ORM configuration or use pg.Pool directly (without RLS).","message":"PGL does not support all pg.Pool options; notably `statement_timeout` and `query_timeout` are ignored.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'automat':69 'boilerpl':71 'compar':72 'connect':41 'context':29,68 'databas':40,96 'database-test':95 'direct':83 'drizzl':2,6,22,87,89 'drizzle-orm':88 'drizzle-orm-test':1,5 'drop':13 'drop-in':12 'enabl':21 'helper':63 'integr':51,93 'integration-test':92 'javascript':84 'level':34 'manag':30,43,75 'manual':74 'orm':3,7,23,90 'pg':76,98 'pgsql':18,81 'pgsql-test':17,80 'polici':45 'pool':77 'postgr':54,85 'postgresql':28,86 'provid':60 'quarter':58 'reduc':70 'replac':15 'rls':36,44,67 'role':49 'row':33 'row-level':32 'seamless':26 'secur':35 'set':65 'support':53 'test':4,8,19,37,47,52,62,82,91,94,97 'timescaledb':56 'typescript':99 'updat':57 'use':79 'user':48 'v2.16.0':9 'work':25 'wrap':39","created_at":"2026-06-04T18:49:33.214063+00:00","updated_at":"2026-06-04T18:49:33.214063+00:00","problems":[{"fix":"Ensure your project is configured for ESM (\"type\": \"module\" in package.json) or use dynamic import: const { PGL } = await import('drizzle-orm-test');","cause":"Attempting to import/use PGL in a CommonJS environment without proper ESM handling.","error":"Error: PGL is not a constructor"},{"fix":"Use `import { createDrizzle } from 'drizzle-orm-test'`.","cause":"Trying to use a default import instead of named import.","error":"TypeError: createDrizzle is not a function"},{"fix":"Wrap your test code inside `withRLS(pool, { role: '...' }, async () => { ... })`.","cause":"RLS context was not set before query; withRLS did not execute properly.","error":"Error: current_setting('rls.role') not found"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/constructive-io/constructive","github":"https://github.com/constructive-io/constructive","docs":null,"changelog":null,"pypi":null,"npm":"drizzle-orm-test","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}