Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Node.js
  3. pg-mem

pg-mem

MITTypeScript3.0.1

An in-memory PostgreSQL emulation for unit testing, working in Node.js, Deno, and browsers.

GitHubGitHub
2.3k stars110 forks0 contributors

What is pg-mem?

pg-mem is an in-memory emulation of a PostgreSQL database designed for unit testing. It allows developers to run SQL queries against a simulated PostgreSQL instance without needing a real database server, Docker, or external dependencies. It solves the problem of slow and complex test setups by providing a fast, lightweight alternative that works across Node.js, Deno, and browsers.

Target Audience

Developers writing unit tests for applications that interact with PostgreSQL, especially those using libraries like node-postgres, TypeORM, Knex, or Slonik who need isolated, repeatable database interactions.

Value Proposition

Developers choose pg-mem because it dramatically speeds up test execution by eliminating Docker or PostgreSQL server overhead, offers instant state rollback for test isolation, and supports custom functions and types. Its cross-platform compatibility and adapter shortcuts for popular libraries make integration seamless.

Overview

An in memory postgres DB instance for your unit tests

Use Cases

Best For

  • Unit testing applications that use PostgreSQL without spinning up Docker containers
  • Mocking database interactions in CI/CD pipelines for faster test runs
  • Testing SQL queries and schema migrations in isolation
  • Developing and testing database-driven applications in browser or Deno environments
  • Creating reproducible test scenarios with custom PostgreSQL functions and types
  • Intercepting and inspecting SQL queries for debugging during tests

Not Ideal For

  • Production environments requiring full PostgreSQL feature compliance and accurate performance profiling
  • Applications that heavily rely on advanced PostgreSQL features like timezone support, precise numeric types, or materialized views
  • Teams needing to test with native PostgreSQL extensions (e.g., uuid-ossp) without manual mocking efforts
  • Complex query optimization testing where real PostgreSQL index behavior and execution plans are critical

Pros & Cons

Pros

Lightning-Fast Test Setup

Runs entirely in memory without Docker or server overhead, drastically reducing test execution time compared to traditional PostgreSQL instances.

Instant State Rollback

Uses immutable data structures to create and restore database snapshots instantly, enabling perfect test isolation without reinitializing schemas.

Seamless Library Integration

Provides built-in adapters for popular libraries like TypeORM, Knex, and node-postgres, allowing existing code to bind to pg-mem with minimal changes.

Custom Function Support

Allows registration of custom SQL functions and user-defined types, facilitating testing of application-specific database logic without real PostgreSQL.

Cons

Incomplete PostgreSQL Support

Uses a home-made SQL parser that doesn't implement all PostgreSQL syntax, and lacks features like timezone handling and proper numeric type emulation, as admitted in the README.

Basic Index Implementation

Index optimizations are rudimentary; complex queries may not be optimized as in real PostgreSQL, potentially leading to misleading performance insights in tests.

No Native Extensions

Native PostgreSQL extensions are not supported, requiring developers to manually mock them using custom functions, which adds overhead and may not replicate real behavior accurately.

Frequently Asked Questions

Quick Stats

Stars2,338
Forks110
Contributors0
Open Issues190
Last commit3 months ago
CreatedSince 2020

Tags

#hacktoberfest#unit-testing#deno#nodejs#typescript#postgresql#typeorm#testing-tools#in-memory-database#browser#unit-tests

Built With

T
TypeScript

Included in

Node.js65.5k
Auto-fetched 1 day ago

Related Projects

PrismaPrisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

Stars46,228
Forks2,238
Last commit3 days ago
TypeORMTypeORM

TypeScript & JavaScript ORM for Node.js — supports PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, and more.

Stars36,529
Forks6,568
Last commit4 days ago
Drizzle ORMDrizzle ORM

ORM

Stars34,711
Forks1,427
Last commit3 days ago
SequelizeSequelize

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB, DB2 and DB2 for IBM i.

Stars30,355
Forks4,339
Last commit7 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub