An in-memory PostgreSQL emulation for unit testing, working in Node.js, Deno, and browsers.
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.
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.
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.
An in memory postgres DB instance for your unit tests
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Runs entirely in memory without Docker or server overhead, drastically reducing test execution time compared to traditional PostgreSQL instances.
Uses immutable data structures to create and restore database snapshots instantly, enabling perfect test isolation without reinitializing schemas.
Provides built-in adapters for popular libraries like TypeORM, Knex, and node-postgres, allowing existing code to bind to pg-mem with minimal changes.
Allows registration of custom SQL functions and user-defined types, facilitating testing of application-specific database logic without real PostgreSQL.
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.
Index optimizations are rudimentary; complex queries may not be optimized as in real PostgreSQL, potentially leading to misleading performance insights in tests.
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.