npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pilaniaanand/driver-postgres

v0.6.0

Published

Readme

@pilaniaanand/driver-postgres

PostgreSQL driver for db-viewer, implementing DatabaseDriver from @pilaniaanand/driver-interface on top of pg and pg-cursor.

Install

npm install @pilaniaanand/driver-postgres

(Or via db-viewer's own driver manager: db-viewer driver add postgres.)

Connecting

Standard host/port/database/username/password, plus:

  • TLS, including client-certificate auth — ssl: true for a plain toggle, or ssl: { enabled: true, ca, cert, key, rejectUnauthorized } with PEM contents pasted/uploaded directly (no temp files).
  • SSH tunnel, for an RDS/Cloud SQL instance sitting in a private subnet behind a bastion — sshTunnel: { enabled: true, host, username, privateKey, passphrase }. privateKey accepts OpenSSH PEM or PuTTY PPK contents; the format is auto-detected. Handled entirely by the server (it opens the tunnel and rewrites host/port before calling this driver), so nothing here is tunnel-aware.
  • readOnly: true — blocks every write through this connection at the server layer, before any driver method runs.

What this driver supports

  • Cursor/keyset pagination (WHERE (pk1, pk2, ...) > (v1, v2, ...), never OFFSET), including composite primary keys and a ctid fallback for tables with no primary key.

  • Exact row counts are real, cancellable queries — cancelling calls pg_cancel_backend on the actual backend PID, not just aborting the HTTP request.

  • Streaming query results via pg-cursor, so the SQL editor and CSV/NDJSON export never buffer a full result set in memory.

  • Real CDC. On first watch of a table, this driver installs a trigger (__dbviewer_watch) and a shared function (__dbviewer_notify_change) that calls pg_notify on every row change, then LISTENs on one shared channel for the whole connection — so external writes (psql, another application, a cron job) show up as live updates too, not just changes made through db-viewer itself. The trigger is dropped automatically when the connection closes.

    This trigger is defensive by design: pg_notify's payload has a hard ~8000-byte limit, so a wide row (a large text/jsonb/encrypted-blob column) falls back to a row-less "something changed" signal instead of overflowing it, and the whole notify path is wrapped in EXCEPTION WHEN OTHERS THEN NULL — a bug in this mechanism can never abort the write that triggered it, whether that write came from db-viewer or any other application sharing the database.

Identifier safety

Every table/schema/column name that reaches this driver from a structured request (not the free-form SQL editor) is validated with assertSafeIdentifier before being interpolated into a query string — SQL has no bind-parameter mechanism for identifiers, so this is the actual injection defense for queryRows filters and insertRow/updateCell/ deleteRow. Values are always parameterized ($1, $2, ...).

Known limitations

  • No schema-per-table watch limit — CDC is per (schema, table), so watching many tables installs many triggers (each cheap, but real DDL objects on your database).
  • sslmode=require-only servers work via the plain ssl: true toggle; verify-full needs a CA cert supplied through SslConfig.ca.