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.1

Published

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

Readme

@rawsql-ts/testkit-postgres

@rawsql-ts/testkit-postgres contains the Postgres-specific rewrite and fixture helpers without bundling a SQL driver. It treats rewritten SQL as a pure transformation and lets you plug in any executor that satisfies the (sql, params) => Promise<Row[]> contract.

Installation

pnpm add -D @rawsql-ts/testkit-postgres

Creating a Postgres testkit client

import path from 'node:path';
import { createPostgresTestkitClient, type QueryExecutor } from '@rawsql-ts/testkit-postgres';

const executor: QueryExecutor = async (sql, params) => {
  // Delegate to your preferred driver/pool and return the rows directly.
  return [{ id: 1, email: '[email protected]' }];
};

const client = createPostgresTestkitClient({
  queryExecutor: executor,
  tableDefinitions: [
    {
      name: 'users',
      columns: [
        { name: 'id', typeName: 'int', required: true },
        { name: 'email', typeName: 'text', required: true },
      ],
    },
  ],
  ddl: { directories: [path.join('ztd', 'ddl')] },
});

const result = await client.query('select id, email from users where id = $1', [1]);
console.log(result.rows); // => [{ id: 1, email: '[email protected]' }]

The package does not close connections or hold onto drivers; the executor you provide manages opening, pooling, and releasing resources. When you need drop-in shorthand helpers (createPgTestkitClient, createPgTestkitPool, wrapPgClient), install the companion @rawsql-ts/adapter-node-pg package that wires this core to Node’s pg module.

QueryExecutor contract

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

Every rewrite runs through ResultSelectRewriter, DefaultFixtureProvider, and TableNameResolver. You can inspect or extend the fixture metadata via:

  • resolveFixtureState(options, tableNameResolver) — merges DDL fixtures, explicit definitions, and user rows.
  • validateFixtureRowsAgainstTableDefinitions(...) — ensures every fixture column/table is defined.

Fixture loading & precedence

Fixtures combine in deterministic layers:

  1. DDL-driven fixtures (ddl.directories) load first and populate schema metadata.
  2. tableDefinitions and tableRows passed to createPostgresTestkitClient override/augment the DDL metadata.
  3. client.withFixtures([...]) layers scenario-specific rows on top before each query.

DDL directories are read once when you create the client, and every subsequent rewrite reuses that snapshot plus any in-memory overrides.

Testing

Run pnpm --filter @rawsql-ts/testkit-postgres test to exercise the driver-agnostic unit tests that validate fixture validation, diagnostics, and executor wiring without depending on Docker or a running Postgres instance.