| Crates.io | mockgres |
| lib.rs | mockgres |
| version | 0.0.8 |
| created_at | 2025-12-01 19:38:28.786866+00 |
| updated_at | 2026-01-19 18:29:38.396205+00 |
| description | An in-memory database that replicates a reasonable subset of Postgres functionality to make unit tests that rely on a database to run. |
| homepage | |
| repository | https://github.com/mockgres/mockgres |
| max_upload_size | |
| id | 1960493 |
| size | 795,652 |
In-memory Postgres-compatible engine for tests.
Mockgres was born out of my frustration for the Postgres docker container taking too long, in my opinion, to start up. I didn't want to have to write mocks, but I also wanted my unit tests to run as fast as possible. I also didn't want to have to manage local installations and cleaning up in between test runs.
Mockgres aims to replicate a reasonable subset of Postgres functionality and semantics for two use cases.
The first use case is that of a typical CRUD app. The second use case is for a basic task queue using SELECT FOR UPDATE SKIP LOCKED.
cargo.cargo run -p mockgres --bin mockgres -- --host 127.0.0.1 --port 6543cargo run -p mockgres --bin mockgres -- 127.0.0.1:6543psql -h 127.0.0.1 -p 6543 postgresSet the bind address via CLI options or MOCKGRES_ADDR.
The CLI accepts --host, --port, or a positional host:port string.
You can technically run it by embedding it as a library, all you really need to do is what's specified in main.
cargo fmt --allcargo clippy --workspace --all-targets -- -D warningscargo test --workspace
Testing covered pretty much exclusively by integration tests in the tests directory.mockgres_freeze() and per-session mockgres_reset().mockgres_freeze(), mockgres_reset())pg_catalog.pg_namespace, pg_catalog.pg_type seeded for builtin typesSELECT mockgres_freeze();. The first call captures a base snapshot; subsequent calls are no-ops and return true.SELECT mockgres_reset(); to discard that session’s sandbox and reclone from the frozen base on next use.mockgres_reset() at the start of each test when reusing a pooled client).Example (psql):
-- Seed baseline and freeze
create table items(id int primary key, label text);
insert into items values (1, 'a');
select mockgres_freeze(); -- returns t
-- Session A (shared DB) mutates baseline
insert into items values (2, 'b');
-- Session B (new connection) gets isolated sandbox
insert into items values (3, 'c');
select id from items order by id; -- sees 1,3 (not Session A’s 2)
-- Reset Session B sandbox (e.g., between tests)
select mockgres_reset(); -- returns t
select id from items order by id; -- back to frozen base: 1
tbd
Aims to be compatible with at least 1-2 most recent versions of Postgres.
tbd
MIT