Skip to content

PostgresAuditSink

Defined in: packages/pipeline-audit/src/sinks/postgres.sink.ts:99

AuditSink backed by Postgres (pg) — a drop-in replacement for the console sink. begin inserts a pending row when an operation starts, and write completes it under the same id (or inserts it, when no pending row exists), so an operation interrupted by a process stop stays visible as 'pending'.

Create the table once with createAuditTableSql. The table name is validated as a plain SQL identifier (it is interpolated, not parameterized); all record values are passed as bound parameters. A NUL character or a lone surrogate, which jsonb rejects, is stored as U+FFFD (see toPostgresJson), so one such character cannot lose the whole record.

import { Pool } from 'pg';
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
await pool.query(createAuditTableSql());
const sink = new PostgresAuditSink(pool);

new PostgresAuditSink(db, options?): PostgresAuditSink

Defined in: packages/pipeline-audit/src/sinks/postgres.sink.ts:103

PostgresQueryableLike

PostgresAuditSinkOptions = {}

PostgresAuditSink

begin(record): Promise<void>

Defined in: packages/pipeline-audit/src/sinks/postgres.sink.ts:127

Inserts the pending row of an operation about to run.

AuditStartRecord

Promise<void>

AuditSink.begin


write(record): Promise<void>

Defined in: packages/pipeline-audit/src/sinks/postgres.sink.ts:135

Inserts the final row, or completes the pending row that begin inserted under the same id.

AuditRecord

Promise<void>

AuditSink.write