Skip to content

launchql/drizzle-test-suite

Repository files navigation

drizzle-orm-test test suite


drizzle-orm-test demo

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.

What is drizzle-orm-test?

drizzle-orm-test provides a testing utility for Drizzle ORM with isolated PostgreSQL databases and transaction-based cleanup between tests.

Usage

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);
  });
});

RLS Testing

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!

Developing

docker-compose up
pnpm install
cd packages/drizzle
pnpm test:watch

Education and Tutorials

  1. 🚀 Quickstart: Getting Up and Running Get started with modular databases in minutes. Install prerequisites and deploy your first module.

  2. 📦 Modular PostgreSQL Development with Database Packages Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.

  3. ✏️ Authoring Database Changes Master the workflow for adding, organizing, and managing database changes with pgpm.

  4. 🧪 End-to-End PostgreSQL Testing with TypeScript Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.

  5. Supabase Testing Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.

  6. 💧 Drizzle ORM Testing Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.

  7. 🔧 Troubleshooting Common issues and solutions for pgpm, PostgreSQL, and testing.

Credits

🛠 Built by LaunchQL — checkout our github ⚛️

Disclaimer

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.

About

A friendly playground for building, testing and validating Drizzle ORM Row‑Level Security (RLS)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published