interface PostgresConnector
extends DBConnector

PostgreSQL database connector.

Methods

connect(signal?: AbortSignal): Promise<DBAdapter>

Connects and returns a DBAdapter for query execution.

end(): Promise<void>

Closes the connection pool.

listen(channel: string): Task<Channel<Notification, ListenFailed>, ListenFailed>

Subscribe to a PostgreSQL NOTIFY channel.

Resolves once the dedicated connection is established and LISTEN is issued. The channel streams notifications until closed or the connection drops. Each active subscription holds a dedicated pg.Client connection.

Cleanup (UNLISTEN + disconnect) runs when the consumer stops iterating, for example after take(), takeWhile(), or exhausting the stream. Calling ch.close() without consuming does not trigger cleanup. The dedicated pg.Client stays connected until the channel is iterated and the generator finalizes.

notify(
channel: string,
payload: string
): Task<void, ListenFailed>

Publish a notification to a channel.

Usage

import { type PostgresConnector } from ".";