Shipping psql without psql: a pure-TypeScript Postgres client in neonctl
neonctl now embeds a pure-TypeScript reimplementation of psql that activates when no native psql is on the PATH. It covers the REPL, all backslash commands, output formats, connection options, SCRAM and TLS, with no native dependencies, and it was written almost entirely by Claude Code under human review. Correctness rests on a conformance harness that fetches PostgreSQL's own regression scripts and diffs output byte-for-byte against a containerized server across PG 14–18, plus an adversarial security review that caught plausible-looking bugs such as a silent sslmode downgrade and a skippable SCRAM mutual-auth check. Lessons include regression-suite hidden setup (prerequisite tables, injected settings), fixing the first diff mismatch rather than the last, and runtime-dependent TLS behavior (BoringSSL under Bun vs OpenSSL under Node).
Related posts
- psql from the browser
Neon easyNovice
psql.sh is a browser-based emulation of Postgres's psql client, built on Neon's WebSocket proxy and serverless driver because browsers can't open raw TCP connections. Each session gets a fresh, isolated database by creating a child branch from a template branch, which yields a connection string almost instantly. Slash commands like \d reuse the Neon SQL Editor's library. The terminal UI was built from scratch instead of using xterm.js, since only a psql session needs emulating. The project is open source.
- @neondatabase/serverless hits 1.0.0
Neon mediumAdept
Neon's JavaScript/TypeScript serverless driver, which carries Postgres queries over HTTP and WebSockets for environments without raw TCP such as V8 isolates and browsers, reaches 1.0.0 after a refactor that adds auto-generated types via api-extractor and CI tests across Node, Bun, Deno, browsers, Cloudflare Workers, Vercel and the Prisma/Drizzle adapters. Tagged-template queries are now composable, because placeholder numbering is deferred until execution. A breaking change makes calling sql(...) as a plain function an error, since that form used ordinary string interpolation and invited SQL injection. New sql.query and sql.unsafe helpers cover the parameterized and trusted-raw-SQL cases. Binary inserts over HTTP now hex-encode roughly 10x faster, though WebSockets remain the recommended path for large blobs.
- Edge-compatible Serverless Driver for Postgres
Neon mediumAdept
Neon's @neondatabase/serverless driver lets V8-isolate platforms like Cloudflare Workers, which lack TCP, speak the real Postgres wire protocol by tunnelling it over a WebSocket to an open-source Go proxy that relays to TCP. The driver is node-postgres with shims for Node APIs, and it does end-to-end TLS 1.3 via WolfSSL compiled to WebAssembly with Asyncify, offloading crypto to SubtleCrypto. Because SCRAM-SHA-256's 4,096 hash rounds exceed Workers' 10–50ms CPU limits, it falls back to cleartext auth over mandatory TLS. The post also covers latency tradeoffs from the extra proxy hop, round-trip reductions, and how to self-host the proxy for any Postgres.
- Web-based AI SQL Playground and connecting to Postgres from the browser
Neon mediumAdept
Neon's Postgres AI Playground connects to a Postgres database directly from the browser and uses OpenAI's gpt-3.5-turbo to turn natural-language prompts into SQL. Browsers can't open TCP connections, so the Neon serverless driver tunnels the Postgres wire protocol through a WebSocket-to-TCP proxy. The proxy is open source and can be self-hosted to reach other Postgres providers. A Vercel edge function rate-limits requests with Upstash Redis, injects the user's schema (pulled from information_schema.columns and flattened to a compact text form) into the prompt, and streams the model's response back to the editor.
- How Does psql -h pg.neon.tech Work?
Neon mediumAdept
Neon's passwordless `psql -h pg.neon.tech` connects to a "Link Proxy", a server that speaks the Postgres wire protocol, rather than to a real Postgres instance. The proxy answers the client's startup message with AuthenticationOk followed by a NoticeResponse, which psql prints as a welcome message containing an auth URL. Visiting that URL opens a control-plane UI where the user picks a project and endpoint. The control plane then sends the connection details for that request ID back to the data-plane proxy, which connects to the chosen compute and relays all traffic to psql.