npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rawsql-ts/testkit-postgres

v0.15.5

Published

Postgres-specific fixture/rewriter logic that stays driver-agnostic.

Downloads

363

Readme

@rawsql-ts/testkit-postgres

npm version License: MIT

Postgres-specific fixture and rewriter logic that stays driver-agnostic. Rewritten SQL is a pure transformation — plug in any executor matching the (sql, params) => Promise<Row[]> contract.

Features

  • Postgres-specific CTE rewriting without bundling a SQL driver
  • Generated fixture manifests first, with DDL-driven fallback for bootstrap or legacy layouts
  • Fixture validation against table definitions
  • Works with any executor (pg, pg-promise, Drizzle, Prisma, etc.)

Installation

npm install @rawsql-ts/testkit-postgres

Quick Start

import { createPostgresTestkitClient, type QueryExecutor } from '@rawsql-ts/testkit-postgres';
import { generatedFixtureManifest } from './tests/generated/ztd-fixture-manifest.generated.js';

const executor: QueryExecutor = async (sql, params) => {
  return [{ id: 1, email: '[email protected]' }];
};

const client = createPostgresTestkitClient({
  queryExecutor: executor,
  generated: generatedFixtureManifest,
});

const result = await client.query('SELECT id, email FROM users WHERE id = $1', [1]);

Schema Resolution

createPostgresTestkitClient lets you pin a default schema and a search path so unqualified table names resolve the same way your starter project does. That keeps schema-qualified definitions readable while still letting tests query through the short table name.

const client = createPostgresTestkitClient({
  queryExecutor: executor,
  defaultSchema: 'public',
  searchPath: ['public'],
  tableDefinitions: [
    {
      name: 'public.users',
      columns: [
        { name: 'id', typeName: 'int', required: true },
        { name: 'email', typeName: 'text', required: true }
      ]
    }
  ],
  tableRows: [
    { tableName: 'public.users', rows: [{ id: 1, email: '[email protected]' }] }
  ]
});

The package does not close connections or hold onto drivers — the executor you provide manages pooling and resources. For drop-in pg helpers (createPgTestkitClient, createPgTestkitPool, wrapPgClient), see @rawsql-ts/adapter-node-pg.

Note: Transaction commands (BEGIN / COMMIT / ROLLBACK) used within testkit are for test isolation only. In production code, transaction boundaries and connection lifecycle are the caller's responsibility — not a concern of the query catalog or fixture layer. See the Execution Scope guide for details.

Fixture Loading & Precedence

Fixtures combine in deterministic layers:

  1. Generated fixture manifests from ztd-config populate schema metadata (tableDefinitions) first.
  2. tableDefinitions / tableRows passed to createPostgresTestkitClient override or augment the generated metadata when a test wants explicit fixtures.
  3. client.withFixtures([...]) layers scenario-specific rows on top before each query.
  4. ddl.directories remains available as a legacy fallback when no generated manifest is supplied.

DDL directories are only scanned when no generated manifest is supplied. In the normal path, createPostgresTestkitClient uses generated metadata directly and skips raw DDL scanning altogether.

Representative benchmark after a workspace build: pnpm bench:testkit-postgres-runtime-metadata compares the generated-manifest cold start with the legacy ddl.directories path on a synthetic large schema.

QueryExecutor Contract

(sql: string, params: readonly unknown[]) => Promise<Record<string, unknown>[]>;

You can inspect or extend fixture metadata via resolveFixtureState() and validateFixtureRowsAgainstTableDefinitions().

License

MIT