Adapter connecting pg (node-postgres) Client/Pool APIs to @rawsql-ts/testkit-postgres. All rewriting and fixture logic is delegated to the driver-agnostic package.
- Drop-in helpers for
pg.Clientandpg.Pool - Named parameter support (
:user_idcompiled to$1) - Reuses fixture validation and schema snapshot from
@rawsql-ts/testkit-postgres
npm install @rawsql-ts/adapter-node-pg pg@rawsql-ts/testkit-postgres is installed automatically as a dependency.
import { createPgTestkitClient } from '@rawsql-ts/adapter-node-pg';
const client = createPgTestkitClient({
connectionFactory: () => pool.connect(),
tableDefinitions: [
{
name: 'users',
columns: [
{ name: 'id', typeName: 'int', required: true },
{ name: 'email', typeName: 'text', required: true },
],
},
],
tableRows: [
{ tableName: 'users', rows: [{ id: 1, email: 'alice@example.com' }] },
],
});
const result = await client.query('SELECT id, email FROM users WHERE id = $1', [1]);| Function | Description |
|---|---|
createPgTestkitClient(options) |
Creates a PgTestkitClient that lazily opens a pg connection and rewrites queries using fixtures. |
createPgTestkitPool(connectionString, ...fixtures) |
Builds a pg.Pool whose client constructor is replaced with PgTestkitClient. |
wrapPgClient(client, options) |
Wraps an existing pg.Client or pg.Pool so queries flow through fixtures without touching your schema. |
All helpers accept the same fixture configuration (tableDefinitions, tableRows, ddl, missingFixtureStrategy, etc.) and pass onExecute hooks through to @rawsql-ts/testkit-postgres.
MIT