npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

drizzle-pgmem

v0.6.2

Published

Improved integration helpers between Drizzle ORM and pg-mem.

Downloads

427

Readme

drizzle-pgmem

Tiny utilities to smooth Drizzle ORM on top of pg-mem for fast in-memory testing.

Permanent shims (always on)

Applied automatically every time you call applyIntegrationsToPool (not user-configurable):

| Shim | Purpose | |------|---------| | rowMode shim | Strips rowMode from query configs so pg-mem accepts queries Drizzle emits (esp. for destructured selects). | | getTypeParser shim | Provides a minimal getTypeParser + internal _types holder and hides any query.types object so pg-mem won't throw. Required for newer Drizzle ORM + migrator code paths. |

These shims are foundational, always safe, and idempotent (calling applyIntegrationsToPool multiple times won't re‑wrap endlessly).

Optional integrations

Optional integrations can be selectively enabled or disabled. They are applied in a deterministic alphabetical order so wrapper layering is stable across runs.

| Integration Name | Description | |----------------------|-----------------| | arrayRowToObject | Converts array-mode or aliased rows into object-shaped rows, enabling property access by column name after destructuring. | | countToValue | Normalizes COUNT(*) results from { count: number } to { value: string } for compatibility with some Drizzle patterns. | | randomFunctionPolyfill | Provides missing PostgreSQL random() in pg-mem, installed lazily on first query. |

Deterministic apply order (alphabetical): arrayRowToObject, countToValue, randomFunctionPolyfill.

Install

npm install -D drizzle-pgmem drizzle-orm pg-mem

Quick start

// test/db.ts (or similar)
import { newDb } from 'pg-mem';
import { drizzle } from 'drizzle-orm/node-postgres';
import { applyIntegrationsToPool } from 'drizzle-pgmem';

export function makeMemDb() {
	const db = newDb();
	const { Pool } = db.adapters.createPg();
	const pool = new Pool();

	// Apply optional integrations (rowMode shim is always applied internally)
	applyIntegrationsToPool(pool);

	const d = drizzle(pool);
	return { pool, db: d, close: () => pool.end() };
}

Example: select a record doesn't fail anymore (thanks to built-in shim)

import { serial, text, pgTable } from 'drizzle-orm/pg-core';
import { makeMemDb } from './test/db';

const people = pgTable('people', {
	id: serial('id').primaryKey(),
	name: text('name').notNull(),
});

const { db, pool } = makeMemDb();
await pool.query(`create table if not exists people (
	id serial primary key,
	name text not null
)`);

await db.insert(people).values({ name: 'Alice' });
const [record] = await db.select({ id: people.id }).from(people);
console.log(!!record); // true if a row exists

Example: enable only a specific integration

import { newDb } from 'pg-mem';
import { drizzle } from 'drizzle-orm/node-postgres';
import { applyIntegrationsToPool } from 'drizzle-pgmem';

const db = newDb();
const { Pool } = db.adapters.createPg();
const pool = new Pool();

// Enable only the countToValue integration (others disabled)
applyIntegrationsToPool(pool, { activeIntegrations: ['countToValue'] });

const d = drizzle(pool);

Active and inactive integrations

The following options allow you to control which optional integrations run. (Permanent shims always run.)

  • activeIntegrations: An array of optional integration names (IntegrationName[]) that explicitly enables only the listed integrations. Any optional integrations not listed here will be disabled.
  • inactiveIntegrations: An array of optional integration names (IntegrationName[]) that explicitly disables the listed integrations. Any optional integrations not listed here will remain enabled by default.

Edge Cases:

  1. Precedence: If both activeIntegrations and inactiveIntegrations are provided, activeIntegrations wins (others are ignored).
  2. Empty Arrays:
    • activeIntegrations: [] => disable all optional integrations.
    • inactiveIntegrations: [] => (same as omitting it) all optional integrations stay enabled.
  3. Omitted Options: If neither option is set, all optional integrations are enabled.
  4. Unknown Names: Silently ignored.
  5. Idempotent: Calling applyIntegrationsToPool more than once is safe; previously wrapped pools won't double-wrap.

Common scenarios

Disable exactly one integration:

applyIntegrationsToPool(pool, { inactiveIntegrations: ['randomFunctionPolyfill'] });

Disable all optional integrations (only permanent shims remain):

applyIntegrationsToPool(pool, { activeIntegrations: [] });

Enable just two integrations:

applyIntegrationsToPool(pool, { activeIntegrations: ['arrayRowToObject', 'countToValue'] });

Provide both (only activeIntegrations is considered):

applyIntegrationsToPool(pool, {
	activeIntegrations: ['countToValue'],
	inactiveIntegrations: ['arrayRowToObject', 'randomFunctionPolyfill'] // ignored
});

TypeScript

Union of integration names is exported as IntegrationName:

import type { IntegrationName } from 'drizzle-pgmem';
// IntegrationName = 'arrayRowToObject' | 'countToValue' | 'randomFunctionPolyfill'

Why alphabetical order?

Predictable layering prevents subtle differences in how wrappers compose (e.g. a row shape transformer should run before a count normalizer, etc.). If a new integration is added, the order remains stable because it's inserted by name.

FAQ

Q: Can I re-run applyIntegrationsToPool on the same pool? A: Yes, it's safe; guards prevent duplicate wrapping.

Q: Why is getTypeParser permanent instead of optional? A: Newer Drizzle code paths (including the migrator) call client.getTypeParser or use query.types. pg-mem doesn't implement this API and throws without the shim, so it's foundational for functionality—not a tweak.

Q: Does this change any production runtime behavior? A: No. It's intended for in-memory testing with pg-mem. The shims/polyfills only adapt incompatibilities; logic stays equivalent to a real Postgres + node-postgres environment where possible.