In-memory PostgreSQL database factory for testing — server environment only. Uses PGlite to spin up a real Drizzle ORM database with the full Esposter schema applied, without needing a running Postgres instance.
@esposter/db-mock is a devDependency — import it only in test files:
import { createMockDb } from "@esposter/db-mock";
const db = await createMockDb();
// db is a fully-typed PostgresJsDatabase with all Esposter schemas applied
We highly recommend you take a look at the documentation to level up.
createMockDb() does the following on each call:
relations config from @esposter/db-schema.drizzle-kit/api-postgres).Each test gets a fresh, isolated database — no cleanup required.
pnpm i -D @esposter/db-mock @electric-sql/pglite drizzle-kit drizzle-orm @esposter/db-schema
Run from packages/db-mock/:
pnpm build # compile to dist/
pnpm lint:fix # auto-fix lint
pnpm typecheck # type check
This project is licensed under the Apache-2.0 license.