This demo shows how to use drizzle-orm-test for fast, isolated PostgreSQL testing with Drizzle ORM. The package is powered by drizzle-orm-test.
drizzle-orm-test provides a testing utility for Drizzle ORM with isolated PostgreSQL databases and transaction-based cleanup between tests.
Here's how to use it:
import { drizzle } from 'drizzle-orm/node-postgres';
import { getConnections, PgTestClient } from 'drizzle-orm-test';
let db: PgTestClient;
let pg: PgTestClient;
let teardown: () => Promise<void>;
beforeAll(async () => {
({ pg, db, teardown } = await getConnections());
});
afterAll(async () => { await teardown(); });
beforeEach(async () => { await db.beforeEach(); });
afterEach(async () => { await db.afterEach(); });
describe('your tests', () => {
it('should work with standard Drizzle pattern', async () => {
const drizzleDb = drizzle(db.client);
const result = await drizzleDb.execute('select 1 as num');
expect(result.rows[0].num).toBe(1);
});
});Test Row Level Security with context management:
it('user should only see their own rows', async () => {
db.setContext({
role: 'authenticated',
'jwt.claims.user_id': '1'
});
const drizzleDb = drizzle(db.client);
const rows = await drizzleDb.select().from(users);
expect(rows.every(r => r.userId === '1')).toBe(true);
});Check out the package source and test examples to see how it works!
docker-compose up
pnpm install
cd packages/drizzle
pnpm test:watch-
🚀 Quickstart: Getting Up and Running Get started with modular databases in minutes. Install prerequisites and deploy your first module.
-
📦 Modular PostgreSQL Development with Database Packages Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
-
✏️ Authoring Database Changes Master the workflow for adding, organizing, and managing database changes with pgpm.
-
🧪 End-to-End PostgreSQL Testing with TypeScript Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
-
⚡ Supabase Testing Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
-
💧 Drizzle ORM Testing Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
-
🔧 Troubleshooting Common issues and solutions for pgpm, PostgreSQL, and testing.
🛠 Built by LaunchQL — checkout our github ⚛️
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.