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.
Example
Section titled “Example”import { Pool } from 'pg';const pool = new Pool({ connectionString: process.env.DATABASE_URL });await pool.query(createAuditTableSql());const sink = new PostgresAuditSink(pool);Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PostgresAuditSink(
db,options?):PostgresAuditSink
Defined in: packages/pipeline-audit/src/sinks/postgres.sink.ts:103
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”PostgresAuditSink
Methods
Section titled “Methods”begin()
Section titled “begin()”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.
Parameters
Section titled “Parameters”record
Section titled “record”Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”write()
Section titled “write()”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.
Parameters
Section titled “Parameters”record
Section titled “record”Returns
Section titled “Returns”Promise<void>