$ show porsager/postgres
porsager/postgres is a PostgreSQL client library for Node.js, Deno, and Cloudflare Workers. It provides a full-featured, performant interface to PostgreSQL using tagged template literals for safe, parameterized queries. The library implements the PostgreSQL wire protocol from scratch with zero runtime dependencies, supporting advanced features like connection pooling, prepared statements, cursors, COPY streams, logical replication, large objects, and custom type mapping. The architecture is a factory function that returns a `sql` tagged template function, which lazily connects to the database and pipelines queries over persistent connections. The codebase is well-structured across `src/` with separate modules for connection management, query execution, protocol message building, type serialization/parsing, and error handling. It also includes transpiled builds for CommonJS, Deno, and Cloudflare Workers, each with platform-specific polyfills. The library is actively maintained, has extensive test coverage, and is published under a public domain license.
The LLM identified 3 files worth highlighting for reuse:
A simple, efficient array-based queue that avoids memory leaks by resetting the internal index when it catches up. It provides push() and shift() methods and can be used as a standalone data structure for any queuing need. The implementation is minimal, generic, and easily extractable.
A fluent buffer builder for constructing PostgreSQL protocol messages. Offers chainable methods like .str(), .i32(), .i16(), .char(), .end() to append strings, integers, and characters to an internal buffer. Self-contained and reusable for any binary protocol message construction.
An extensible type serialization and parsing system for PostgreSQL data types. It maintains maps of serializers and parsers keyed by OID, supports custom types, array auto-detection, and column/value/row transforms (camelCase, PascalCase, kebab-case). The module is standalone and can be adapted for other database drivers or data format conversions.