Skip to content

pgListenNotify

function pgListenNotify(client, channel?): WatchSubscribe;

Defined in: src/storage/watch.ts:51

A WatchSubscribe backed by Postgres LISTEN/NOTIFY. Pair with withWatch for the postgres or drizzle-over-pg adapters. Your migration owns the trigger that pg_notifys channel with the changed key as payload; this only LISTENs. client is a dedicated listening connection (a pg Client, not a Pool).

Parameter Type Default value
client PgNotificationClient undefined
channel? string "xtandard_audit"

WatchSubscribe

import { Client } from "pg";
const listener = new Client({ connectionString: process.env.DATABASE_URL });
await listener.connect();
const storage = withWatch(base, pgListenNotify(listener, "xtandard_audit"));