Registry / testing / drizzle-pgmem

drizzle-pgmem

JSON →
library0.6.2jsnpmunverified

Tiny utilities (v0.6.2) that smooth integration of Drizzle ORM with pg-mem for fast in-memory testing. Applies permanent shims for rowMode and getTypeParser, plus optional integrations like arrayRowToObject, countToValue, and randomFunctionPolyfill. Declared stable with deterministic alphabetical integration ordering and idempotent application. Unlike manual shimming, drizzle-pgmem is tested against the specific versions of Drizzle and pg-mem it targets, and provides a simple API to enable/disable integrations. Requires Node >=18 and peer dependencies drizzle-orm and pg-mem.

npm install drizzle-pgmem
INSTALL
IMPORT
SIG · DRIZZLE-PGMEM
D
drizzle-pgmem
testingjavascriptv0.6.2
harness data pending
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.

applyIntegrationsToPool
import { applyIntegrationsToPool } from 'drizzle-pgmem'
const { applyIntegrationsToPool } = require('drizzle-pgmem')
Package is ESM-only; CommonJS require is not supported.
IntegrationName
import type { IntegrationName } from 'drizzle-pgmem'
import { IntegrationName } from 'drizzle-pgmem'
IntegrationName is a type export, not a runtime value. Use `import type` for correctness.
type definition
import { type ApplyIntegrationsOptions } from 'drizzle-pgmem'
import { ApplyIntegrationsOptions } from 'drizzle-pgmem'
If using isolatedModules or verbatimModuleSyntax, you must prefix with `type` to avoid runtime import errors.

Creates an in-memory PostgreSQL database with pg-mem and applies drizzle-pgmem integrations to avoid common Drizzle ORM compatibility issues.

import { newDb } from 'pg-mem'; import { drizzle } from 'drizzle-orm/node-postgres'; import { applyIntegrationsToPool } from 'drizzle-pgmem'; function makeMemDb() { const db = newDb(); const { Pool } = db.adapters.createPg(); const pool = new Pool(); // Apply all optional integrations (rowMode shim is applied automatically internally) applyIntegrationsToPool(pool); const d = drizzle(pool); return { pool, db: d, close: () => pool.end() }; } // Example usage const { db, pool } = makeMemDb(); await pool.query('CREATE TABLE test (id serial primary key, name text)'); await db.execute('INSERT INTO test (name) VALUES ($1)', ['Alice']); const result = await db.execute('SELECT * FROM test'); console.log(result.rows);
Debug
Known issues
gotchaapplyIntegrationsToPool must be called before calling drizzle(pool) – otherwise shims are not applied and queries may fail silently.
fix
Ensure applyIntegrationsToPool(pool) runs before drizzle(pool).
affects: >=0.0.0
gotchaWhen both activeIntegrations and inactiveIntegrations are provided, activeIntegrations wins and inactiveIntegrations is ignored.
fix
Use only one of the two options to avoid confusion.
affects: >=0.0.0
breakingv0.5.0 changed the default integrations set; previously all optional integrations were enabled by default, now only permanent shims run unless activeIntegrations is specified.
fix
Explicitly pass activeIntegrations: ['arrayRowToObject', 'countToValue', 'randomFunctionPolyfill'] if you need the old behavior.
affects: >=0.5.0
deprecatedThe IntegrationName type was renamed in v0.4.0 from IntegrationList to IntegrationName.
fix
Replace any references to IntegrationList with IntegrationName.
affects: >=0.4.0
gotcharandomFunctionPolyfill is installed lazily on first query, but if you rely on random() within Drizzle migrations, it may not be available until after a query is executed.
fix
Ensure at least one query (e.g., SELECT 1) is run before invoking Drizzle migrations that use random().
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'drizzle-pgmem' or its corresponding type declarations.
Package is ESM-only and may not be resolved correctly in a CommonJS project or if type: module is missing.
fix
Add "type": "module" to your package.json, or use .mjs extension for your files. If using TypeScript, set "moduleResolution": "Node16" or "Bundler" in tsconfig.json.
TypeError: pool.query is not iterable
applyIntegrationsToPool wasn't called before using Drizzle ORM pool, so shims are missing.
fix
Call applyIntegrationsToPool(pool) immediately after creating the pool and before passing it to drizzle().
Type error: Module '"drizzle-pgmem"' has no exported member 'IntegrationName'.
IntegrationName is a type, not a value. Importing it without `type` may fail in strict ESM environments.
fix
Use `import type { IntegrationName } from 'drizzle-pgmem'`.
Upgrade
Version history
0.6.2latest on npm
Audit
Dependencies
drizzle-ormrequiredDrizzle ORM is the primary integration target; peer dependency.
pg-memrequiredIn-memory PostgreSQL simulator; peer dependency needed for pool and adapters.
Agent activity
2 hits · last 30 days
node
2
Resources
drizzle-pgmem — npm install drizzle-pgmem · libregistry