Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/pgc4d/src/mod.ts>PgConn

A full-featured PostgreSQL Client for Deno
Latest
interface PgConn
implements [Deno.Closer]
import { type PgConn } from "https://deno.land/x/pgc4d@v1.3.6/src/mod.ts";

Properties

readonly
pid: number

Process ID of the server process attached to the current session. Same as the number returned by pg_backend_pid() function using SQL.

readonly
serverParams: Map<string, string>

The current setting of server parameters such as client_encoding or DateStyle.

readonly
done: Promise<Error | undefined>

Resolved when connection is closed, with Error if due to a problem, or undefined if due to close() being called. Never rejects.

Methods

query(text: string, params?: ColumnValue[]): Promise<BufferedQueryResult>

Executes a query and returns a buffered result once all the rows are received.

queryStreaming(text: string, params?: ColumnValue[]): Promise<StreamingQueryResult>

Executes a query and returns a streaming result as soon as the query has been accepted by the server. Rows will be retrieved as you consume them.

prepare(text: string): Promise<PreparedStatement>

Creates a prepared statement on the server which you can later execute several times using different parameter values. Should offer improved performance compared to executing completely independent queries.

addListener(channel: string, listener: NotificationListener): Promise<void>

Adds a listener for a channel. If this is the first listener for the channel, issues a LISTEN query against the database. Returned promise resolves after the connection is confirmed to be subscribed.

removeListener(channel: string, listener: NotificationListener): Promise<void>

Removes a listener for a channel. Listener is removed immediately and will not receive any further events. If this is the last listener for the channel, issues an UNLISTEN query against the database. Returned promise resolves after the connection is unsubscribed if the last listener is being removed, immediately otherwise.

reloadTypes(): Promise<void>

pgc4d loads the pg_type table to obtain the definitions of user-defined types. You can call reloadTypes() after doing e.g. CREATE TYPE ... AS ENUM to have the type recognized without re-connecting.

close(): void

Closes immediately, killing any queries in progress. They will reject. Not an issue if called multiple times. Subsequent calls will have no effect.