Esposter
    Preparing search index...

    Module @esposter/db-mock - v2.27.0

    @esposter/db-mock

    Apache-2.0 licensed

    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:

    1. Creates a new PGlite in-memory client.
    2. Wraps it with a Drizzle ORM instance using the full relations config from @esposter/db-schema.
    3. Generates migration SQL from the current schema snapshot (via drizzle-kit/api-postgres).
    4. Applies all generated statements so the schema is up to date.

    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.

    Functions

    createMockDb